Closed alabihula closed 2 weeks ago
function errorHandler(error: RequestError): Promise { if (error.response) { const { data = {}, status, statusText } = error.response // 403 无权限 if (status === 403) { showNotify({ type: 'danger', message: (data && data.message) || statusText, }) } // 401 未登录/未授权 if (status === 401 && data.result && data.result.isLogin) { showNotify({ type: 'danger', message: 'Authorization verification failed', }) // 如果你需要直接跳转登录页面 // location.replace(loginRoutePath) } if (status === 500) { showNotify({ type: 'danger', message: (data && data.message) || statusText, }) return Promise.resolve({}) } } return Promise.reject(error) } 使用非200拦截后还是会提示下方错误
errorHandler方法中的任何非200问题 都会出现下方系统报错 而不是自定义弹窗
function errorHandler(error: RequestError): Promise {
if (error.response) {
const { data = {}, status, statusText } = error.response
// 403 无权限
if (status === 403) {
showNotify({
type: 'danger',
message: (data && data.message) || statusText,
})
}
// 401 未登录/未授权
if (status === 401 && data.result && data.result.isLogin) {
showNotify({
type: 'danger',
message: 'Authorization verification failed',
})
// 如果你需要直接跳转登录页面
// location.replace(loginRoutePath)
}
if (status === 500) {
showNotify({
type: 'danger',
message: (data && data.message) || statusText,
})
return Promise.resolve({})
}
}
return Promise.reject(error)
}
使用非200拦截后还是会提示下方错误