easy-temps / vue3-vant-mobile

An mobile web apps template based on the Vue 3 ecosystem。一个基于 Vue 3 生态系统的移动 web 应用模板,帮助你快速完成业务开发。
https://vue3-vant-mobile.netlify.app
MIT License
1.1k stars 219 forks source link

接口500错误怎么捕获自定义弹窗而不是系统层报错 #125

Closed alabihula closed 2 weeks ago

alabihula commented 2 weeks ago
image

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拦截后还是会提示下方错误

image
alabihula commented 2 weeks ago

errorHandler方法中的任何非200问题 都会出现下方系统报错 而不是自定义弹窗