统一前后端代码格式化配置
This commit is contained in:
@@ -24,11 +24,7 @@ export function showError(message: string, options: MessageOptions = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
export function showConfirm(
|
||||
message: string,
|
||||
title = '确认操作',
|
||||
options: ModalFuncProps = {},
|
||||
) {
|
||||
export function showConfirm(message: string, title = '确认操作', options: ModalFuncProps = {}) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
Modal.confirm({
|
||||
title,
|
||||
|
||||
@@ -37,13 +37,9 @@ 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
|
||||
}
|
||||
@@ -56,10 +52,7 @@ 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()
|
||||
|
||||
@@ -75,10 +68,7 @@ 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()
|
||||
|
||||
@@ -126,13 +116,8 @@ 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 '接口请求失败'
|
||||
@@ -158,9 +143,7 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user