Added retries on failed api requests

This commit is contained in:
Patrick Alvin Alcala 2025-11-10 13:41:09 +08:00
parent 91a8f03749
commit 79a3e508dc
2 changed files with 4 additions and 4 deletions

View file

@ -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