From de34f330582fc639b33c95d6b501035e8caf286d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 11 Feb 2024 11:28:57 -0500 Subject: [PATCH] fix: Do not automatically retry failed document import request --- app/stores/DocumentsStore.ts | 4 +++- app/utils/ApiClient.ts | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/stores/DocumentsStore.ts b/app/stores/DocumentsStore.ts index 9814762b8..b29616494 100644 --- a/app/stores/DocumentsStore.ts +++ b/app/stores/DocumentsStore.ts @@ -640,7 +640,9 @@ export default class DocumentsStore extends Store { formData.append(info.key, info.value); } }); - const res = await client.post("/documents.import", formData); + const res = await client.post("/documents.import", formData, { + retry: false, + }); invariant(res?.data, "Data should be available"); this.addPolicies(res.policies); return this.add(res.data); diff --git a/app/utils/ApiClient.ts b/app/utils/ApiClient.ts index f8519fd51..b8ec84e49 100644 --- a/app/utils/ApiClient.ts +++ b/app/utils/ApiClient.ts @@ -26,6 +26,7 @@ type Options = { interface FetchOptions { download?: boolean; + retry?: boolean; credentials?: "omit" | "same-origin" | "include"; headers?: Record; } @@ -99,14 +100,17 @@ class ApiClient { let response; try { - response = await fetchWithRetry(urlToFetch, { - method, - body, - headers, - redirect: "follow", - credentials: "same-origin", - cache: "no-cache", - }); + response = await (options?.retry === false ? fetch : fetchWithRetry)( + urlToFetch, + { + method, + body, + headers, + redirect: "follow", + credentials: "same-origin", + cache: "no-cache", + } + ); } catch (err) { if (window.navigator.onLine) { throw new NetworkError("A network error occurred, try again?");