This commit is contained in:
Patrick Alvin Alcala 2025-11-24 16:33:12 +08:00
parent fe90f5988a
commit 499e1530cc
9 changed files with 195 additions and 9 deletions

View file

@ -1,19 +1,21 @@
import { $backendUrl } from 'configs/config.api'
import { ofetch } from 'ofetch'
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
const URL = $backendUrl.get()
const RETRY = $requestRetries.get()
const CODES = $requestRetryCodes.get()
export default async (api: string, value?: any, value2?: any) => {
try {
let fetch
if (!value2) {
if (!value) {
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] })
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
} else {
fetch = await ofetch(URL + `${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] })
fetch = await ofetch(URL + `${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
}
} else {
fetch = await ofetch(URL + `${api}/${value}/${value2}/fetch-data`, { parseResponse: JSON.parse, retry: 3, retryDelay: 500, retryStatusCodes: [400, 404, 405, 500, 502] })
fetch = await ofetch(URL + `${api}/${value}/${value2}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
}
const result = fetch
return [result, null]