Caught & handled 'resource_already_exists' errors (#185)

refs https://github.com/TryGhost/Ghost/issues/12065

This protects us against multiple instances of the members-api being
started simultaneously and race conditions where inbetween the initial
"GET" of a plan which returns empty, and the "POST" of a plan to create
it, another instance has already created it.
This commit is contained in:
Fabien 'egg' O'Carroll 2020-07-21 13:40:49 +02:00 committed by GitHub
parent 8c73c4a42b
commit d1cd0fe80e

View File

@ -43,7 +43,12 @@ function createCreator(resource, getAttrs) {
stripe,
resource,
Object.assign(getAttrs(object, ...rest), {id})
);
).catch((err) => {
if (err.code !== 'resource_already_exists') {
throw err;
}
return stripeRetrieve(stripe, resource, id);
});
};
}