| | |
| | | import { type IRequestOptions, Request, type RequestConfig } from 'senior-request'; |
| | | import { type AxiosRequestConfig, type AxiosError } from 'axios'; |
| | | import axios, { type AxiosRequestConfig, type AxiosError } from 'axios'; |
| | | import qs from 'qs'; |
| | | import Taro from '@tarojs/taro'; |
| | | import { getToken, Message } from '@/utils'; |
| | |
| | | REDIRECT = 9, |
| | | } |
| | | // 与后端约定的响应数据格式 |
| | | interface ResponseStructure { |
| | | export interface ResponseStructure { |
| | | success: boolean; |
| | | data: any; |
| | | /** |
| | |
| | | withCredentials: true, |
| | | }; |
| | | |
| | | const config: RequestConfig<ResponseStructure, IRequestOptions> = { |
| | | export const config: RequestConfig<ResponseStructure, IRequestOptions> = { |
| | | ...AxiosOptions, |
| | | |
| | | errorConfig: { |
| | | // 错误接收及处理 |
| | | errorHandler: (error, opts) => { |
| | | console.log('error: ', error); |
| | | const userStore = useUserStoreWithOut(); |
| | | logFront({ |
| | | url: opts.url, |
| | | message: JSON.stringify(error), |
| | | requestTime: new Date().toLocaleString(), |
| | | userId: userStore.virtualUserId, |
| | | }); |
| | | if (opts?.skipErrorHandler) throw error; |
| | | |
| | | if (opts?.customErrorHandler) { |
| | |
| | | } |
| | | |
| | | export const request = Request.create(config); |
| | | |
| | | function logFront(body: API.LogFrontInput) { |
| | | return axios.request({ |
| | | baseURL: AxiosOptions.baseURL, |
| | | url: '/api/Log/LogFront', |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | data: body, |
| | | }); |
| | | } |