|  |  |  | 
|---|
|  |  |  | import { ElLoading as Loading, ElNotification } from 'element-plus'; | 
|---|
|  |  |  | import { router } from '@/router'; | 
|---|
|  |  |  | import { Message, tokenIsExpired } from '@/utils'; | 
|---|
|  |  |  | import { httpLoggerRecord } from '../LoggerRecord'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 加载环境变量 VITE_PROXY_DOMAIN(开发环境)  VITE_PROXY_DOMAIN_REAL(打包后的线上环境) | 
|---|
|  |  |  | const { VITE_PROXY_DOMAIN, VITE_PROXY_DOMAIN_REAL, DEV } = loadEnv(); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | msg?: string; | 
|---|
|  |  |  | showType?: ErrorShowType; | 
|---|
|  |  |  | traceId?: string; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | interface ErrorResponse { | 
|---|
|  |  |  | 
|---|
|  |  |  | // 错误接收及处理 | 
|---|
|  |  |  | errorHandler: (error, opts) => { | 
|---|
|  |  |  | console.log('error: ', error); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const url = opts.url ?? ''; | 
|---|
|  |  |  | httpLoggerRecord.error({ | 
|---|
|  |  |  | message: `[${url}] 请求错误`, | 
|---|
|  |  |  | httpParams: { | 
|---|
|  |  |  | url: url, | 
|---|
|  |  |  | //@ts-ignore | 
|---|
|  |  |  | traceId: error?.info?.traceId, | 
|---|
|  |  |  | stackTrace: error.stack, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | args: [{ data: opts.data, params: opts.params, headers: opts.headers }], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (opts?.skipErrorHandler) throw error; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (opts?.customErrorHandler) { | 
|---|
|  |  |  | 
|---|
|  |  |  | NProgress.start(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | httpLoggerRecord.info({ | 
|---|
|  |  |  | message: `[${$config.url}] 请求开始`, | 
|---|
|  |  |  | httpParams: { | 
|---|
|  |  |  | url: $config.url, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | args: [{ data: $config.data, params: $config.params, headers: $config.headers }], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const userStore = useUserStoreHook(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const userInfo = userStore.userInfo; | 
|---|
|  |  |  | 
|---|
|  |  |  | (response) => { | 
|---|
|  |  |  | const $config = response.config as IRequestOptions; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | httpLoggerRecord.info({ | 
|---|
|  |  |  | message: `[${$config.url}] 请求结束`, | 
|---|
|  |  |  | httpParams: { | 
|---|
|  |  |  | url: $config.url, | 
|---|
|  |  |  | traceId: response.data?.traceId, | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | args: [{ data: $config.data, params: $config.params, headers: $config.headers }], | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const { needNProcess, getResponse = false } = $config; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 关闭进度条动画 | 
|---|