Skip to content

Commit

Permalink
Retry tree PUT on 422
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Mar 21, 2022
1 parent f3385fa commit c4e82f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,8 @@ export class OADAClient {
}

async #retryEnsureTree(tree: OADATree, pathArray: readonly string[]) {
// Retry on 412
// Retry on certain errors
const CODES = new Set(<const>['412', '422']);
const MAX_RETRIES = 5;

for await (const retryCount of Array.from({
Expand All @@ -805,7 +806,7 @@ export class OADAClient {
} catch (cError: unknown) {
// Handle 412 (If-Match failed)
// @ts-expect-error stupid errors
if (cError?.code === '412') {
if (CODES.has(cError?.code)) {
await setTimeout(
// Retry with exponential backoff
100 * ((retryCount + 1) ** 2 + Math.random())
Expand Down
1 change: 0 additions & 1 deletion test/put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ for (const connection of <const>['ws', 'http']) {
const response = await getAxios(
`/bookmarks/${testName}/concurrent-put/${v}`
);
t.log(response.data);
t.is(response.status, 200);
t.assert(response.headers['content-location']);
t.assert(response.headers['x-oada-rev']);
Expand Down

0 comments on commit c4e82f8

Please sign in to comment.