kinto.js
kinto.js copied to clipboard
Add a if_not_exists options to create_bucket and create_collection
We did that in the kinto-http.py client so that it tries and fail silently.
Related https://github.com/Kinto/kinto-http.py/pull/48
That means not rejecting when encountering a conflict but getting the resource and resolving with the result instead, right?
If encountering a conflict means raising on safe: false, yes.
Use-case is this: https://github.com/leplatrem/happiness/blob/194d2a21097f0798d200006a9ca166acc5bebc1b/scripts/sagas/poll.js#L13-L24
try {
// Create the bucket in case it doesn't exist.
const permissions = {"collection:create": ["system.Authenticated"]};
yield client.createBucket(bucket, {headers, permissions, safe: true});
} catch(e) {
// Ignore error if it already exists (created by someone else).
if (!/HTTP 403/.test(e.message)) {
throw e;
}
}
If I do a create with safe: true, isn't supposed to issue a If-None-Match: * and thus rejecting with 412 if something exists ?
It depends if you have the permission to know if it exists or not. If you do not have the permission you will have a 403 if you do you will have a 412.