From c4e82f86bd900fbe171c48aae69b0a82f4559e85 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Mon, 21 Mar 2022 18:36:32 -0400 Subject: [PATCH] Retry tree PUT on 422 --- lib/client.ts | 5 +++-- test/put.test.ts | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/client.ts b/lib/client.ts index 5509f07..51253b8 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -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(['412', '422']); const MAX_RETRIES = 5; for await (const retryCount of Array.from({ @@ -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()) diff --git a/test/put.test.ts b/test/put.test.ts index ba6917c..9147a5f 100644 --- a/test/put.test.ts +++ b/test/put.test.ts @@ -290,7 +290,6 @@ for (const connection of ['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']);