up
chenyc
2022-09-09 cf29ab5abf6c5f7b870c4854d37cdd6ec69fda67
src/utils/axios.ts
@@ -29,20 +29,12 @@
/**
 * 错误处理函数
 */
const errorMsgHandler = (code, data): string | undefined => {
const errorMsgHandler = (code:any, data:any): string | undefined => {
    const { message } = data
    const msgMap = {
        400: message || '400 error 请求无效',
        401: '401 error 登录失效,请重新登录!',
        403: '403 error 对不起,你没有访问权限!',
        404: '404 Not Found',
        500: message || '500 error 后台错误,请联系管理员',
        502: '502 error 平台环境异常'
    }
    return msgMap[code]
    return message+'请求错误'
}
const errorHandle = (error): IResponseError => {
const errorHandle = (error:any): IResponseError => {
    const { data, status, statusText } = error.response
    const msg = errorMsgHandler(status, data) || `${status} error ${data ? data.message : statusText}`
    alert(msg)