完善接单平台上传与物品规则
This commit is contained in:
@@ -36,9 +36,13 @@ http.interceptors.response.use(
|
||||
},
|
||||
(error) => {
|
||||
const responseMessage =
|
||||
typeof error?.response?.data?.msg === 'string' ? error.response.data.msg.trim() : ''
|
||||
typeof error?.response?.data?.msg === 'string'
|
||||
? error.response.data.msg.trim()
|
||||
: ''
|
||||
const fallbackMessage = resolveFallbackHttpMessage(error)
|
||||
const normalizedError = new Error(responseMessage || fallbackMessage) as Error & {
|
||||
const normalizedError = new Error(
|
||||
responseMessage || fallbackMessage,
|
||||
) as Error & {
|
||||
errorCode?: string
|
||||
status?: number
|
||||
}
|
||||
@@ -51,7 +55,10 @@ http.interceptors.response.use(
|
||||
normalizedError.status = error.response.status
|
||||
}
|
||||
|
||||
if (error?.config?.url && String(error.config.url).startsWith('/api/v1/admin')) {
|
||||
if (
|
||||
error?.config?.url &&
|
||||
String(error.config.url).startsWith('/api/v1/admin')
|
||||
) {
|
||||
const status = Number(error?.response?.status || 0)
|
||||
const errorCode = String(error?.response?.data?.errorCode || '').trim()
|
||||
|
||||
@@ -67,7 +74,10 @@ http.interceptors.response.use(
|
||||
}
|
||||
}
|
||||
|
||||
if (error?.config?.url && String(error.config.url).startsWith('/api/v1/worker')) {
|
||||
if (
|
||||
error?.config?.url &&
|
||||
String(error.config.url).startsWith('/api/v1/worker')
|
||||
) {
|
||||
const status = Number(error?.response?.status || 0)
|
||||
const errorCode = String(error?.response?.data?.errorCode || '').trim()
|
||||
|
||||
@@ -118,8 +128,13 @@ function resolveFallbackHttpMessage(error: unknown) {
|
||||
return '网络连接错误'
|
||||
}
|
||||
|
||||
if (typeof (error as { response?: { statusText?: string } })?.response?.statusText === 'string') {
|
||||
return String((error as { response: { statusText: string } }).response.statusText).trim()
|
||||
if (
|
||||
typeof (error as { response?: { statusText?: string } })?.response
|
||||
?.statusText === 'string'
|
||||
) {
|
||||
return String(
|
||||
(error as { response: { statusText: string } }).response.statusText,
|
||||
).trim()
|
||||
}
|
||||
|
||||
return '接口请求失败'
|
||||
@@ -145,7 +160,9 @@ function shouldClearWorkerSession(errorCode: string) {
|
||||
].includes(errorCode)
|
||||
}
|
||||
|
||||
function request<T>(config: Parameters<typeof http.request<ApiEnvelope<T>>>[0]) {
|
||||
function request<T>(
|
||||
config: Parameters<typeof http.request<ApiEnvelope<T>>>[0],
|
||||
) {
|
||||
return http.request<ApiEnvelope<T>, ApiEnvelope<T>>(config)
|
||||
}
|
||||
|
||||
@@ -163,7 +180,20 @@ export function apiGetBlob(url: string, params?: Record<string, unknown>) {
|
||||
}
|
||||
|
||||
export function apiPost<T>(url: string, data?: unknown) {
|
||||
return request<T>({ method: 'POST', url, data: data as Record<string, unknown> })
|
||||
return request<T>({
|
||||
method: 'POST',
|
||||
url,
|
||||
data: data as Record<string, unknown>,
|
||||
})
|
||||
}
|
||||
|
||||
export function apiPostForm<T>(url: string, data: FormData) {
|
||||
return request<T>({
|
||||
method: 'POST',
|
||||
url,
|
||||
data,
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
}
|
||||
|
||||
export function apiDelete<T>(url: string) {
|
||||
|
||||
Reference in New Issue
Block a user