From 79a3e508dcd331e56f616fddb8f50ef1e199928d Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Mon, 10 Nov 2025 13:41:09 +0800 Subject: [PATCH] Added retries on failed api requests --- src/utils/functions/getApi.ts | 4 ++-- src/utils/functions/getApiMulti.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/functions/getApi.ts b/src/utils/functions/getApi.ts index 30b4523..c902370 100644 --- a/src/utils/functions/getApi.ts +++ b/src/utils/functions/getApi.ts @@ -6,9 +6,9 @@ export default async (api: string, value?: any) => { try { let fetch if (!value) { - fetch = await ofetch(API + api, { parseResponse: JSON.parse }) + fetch = await ofetch(API + api, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] }) } else { - fetch = await ofetch(API + `${api}/${value}`, { parseResponse: JSON.parse }) + fetch = await ofetch(API + `${api}/${value}`, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] }) } const result = fetch.result return result diff --git a/src/utils/functions/getApiMulti.ts b/src/utils/functions/getApiMulti.ts index 69d1b3e..c595379 100644 --- a/src/utils/functions/getApiMulti.ts +++ b/src/utils/functions/getApiMulti.ts @@ -6,9 +6,9 @@ export default async (api: string, value?: any) => { let fetch try { if (!value) { - fetch = await ofetch(API + api, { parseResponse: JSON.parse }) + fetch = await ofetch(API + api, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] }) } else { - fetch = await ofetch(API + `${api}/${value}`, { parseResponse: JSON.parse }) + fetch = await ofetch(API + `${api}/${value}`, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] }) } return fetch