vue-pro/yudao-ui-app/util/request/responseInterceptors.js
2022-05-02 17:58:48 +08:00

30 lines
803 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 响应拦截
* @param {Object} http
*/
module.exports = vm => {
uni.$u.http.interceptors.response.use(
res => {
//对响应成功做点什么 可使用async await 做异步操作
//可以根据业务情况做相应的处理
if (res.data.code === 0) {
return res.data
} else if(res.data.code === 401) {
//用户未登录或登录token已过期
vm.$store.commit('CLEAR_LOGIN_INFO')
} else {
console.log(res)
//其他错误信息统一处理
uni.$u.toast(res.data.msg)
return Promise.reject(res)
}
},
err => {
//对响应错误做点什么 statusCode !== 200
console.log(err)
uni.$u.toast('响应错误' + err.statusCode)
return Promise.reject(err)
}
)
}