Updated
This commit is contained in:
parent
fe90f5988a
commit
499e1530cc
9 changed files with 195 additions and 9 deletions
|
|
@ -1,3 +1,6 @@
|
|||
import { atom } from 'nanostores'
|
||||
|
||||
export const $backendUrl = atom('http://localhost:8080')
|
||||
|
||||
export const $requestRetries = atom<number>(3)
|
||||
export const $requestRetryCodes = atom<Array<number>>([400, 404, 405, 500, 502])
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import { encryptRsa } from '../../scripts'
|
||||
import { $backendUrl } from 'configs/config.api'
|
||||
import { $tokenExpiration, $tokenName } from 'configs/config.security'
|
||||
import dayjs from 'dayjs'
|
||||
import { ofetch } from 'ofetch'
|
||||
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
|
||||
import { $tokenExpiration, $tokenName } from '../../../../configs/config.security'
|
||||
import { encryptRsa } from '../../scripts'
|
||||
|
||||
const URL = $backendUrl.get()
|
||||
const TOKEN_NAME = $tokenName.get()
|
||||
const TOKEN_EXPIRATION = $tokenExpiration.get()
|
||||
const RETRY = $requestRetries.get()
|
||||
const CODES = $requestRetryCodes.get()
|
||||
|
||||
export default async (api: string, body: Object) => {
|
||||
const today = new Date()
|
||||
|
|
@ -22,9 +24,9 @@ export default async (api: string, body: Object) => {
|
|||
'Cache-Control': 'no-cache',
|
||||
'Dasig-Token': hash,
|
||||
},
|
||||
retry: 3,
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: [400, 404, 405, 500, 502],
|
||||
retryStatusCodes: CODES,
|
||||
method: 'POST',
|
||||
body: body,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue