import { IPlugin } from '../../intf/IPlugin' import { AxiosInstance, AxiosResponse } from 'axios' import { IErrorHandler } from '../../intf/IErrorHandler' /** 异常处理 */ export const errorHandler = (handler: IErrorHandler): IPlugin => { return { pluginName: 'error-handler', handler: (axios: AxiosInstance) => { axios.interceptors.response.use( (res: AxiosResponse) => res, async (e: any) => { await handler(e) throw e } ) } } }