responseInterceptors.js 996 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /**
  2. * 响应拦截
  3. * @param {Object} http
  4. */
  5. module.exports = vm => {
  6. uni.$u.http.interceptors.response.use(
  7. response => {
  8. const data = response.data
  9. // 刷新token
  10. const authorization = response.headers?.authorization
  11. if (authorization) {
  12. vm.$store.dispatch('user/token', authorization)
  13. }
  14. if (data.code !== 0) {
  15. uni.showModal({
  16. title: '提示',
  17. content: data.message,
  18. showCancel: false
  19. })
  20. // 401 登录超时 402 需要登录
  21. if (data.status_code === 401 || data.status_code === 402) {
  22. /* uni.reLaunch({
  23. url: 'pages/index/index'
  24. })*/
  25. }
  26. return Promise.reject(data.message)
  27. }
  28. return data
  29. }, (error) => {
  30. console.error('-->error', error)
  31. // uni.showModal({
  32. // title: '提示',
  33. // content: error.message,
  34. // showCancel: false
  35. // })
  36. return Promise.reject(error)
  37. })
  38. }