kinto.js icon indicating copy to clipboard operation
kinto.js copied to clipboard

Add a if_not_exists options to create_bucket and create_collection

Open Natim opened this issue 9 years ago • 6 comments

We did that in the kinto-http.py client so that it tries and fail silently.

Natim avatar Jun 30 '16 08:06 Natim

Related https://github.com/Kinto/kinto-http.py/pull/48

Natim avatar Jun 30 '16 08:06 Natim

That means not rejecting when encountering a conflict but getting the resource and resolving with the result instead, right?

n1k0 avatar Jun 30 '16 08:06 n1k0

If encountering a conflict means raising on safe: false, yes.

Natim avatar Jun 30 '16 08:06 Natim

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;
    }
  }

leplatrem avatar Jul 04 '16 08:07 leplatrem

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 ?

leplatrem avatar Jul 15 '16 09:07 leplatrem

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.

Natim avatar Jul 18 '16 07:07 Natim