|
|
@@ -43,34 +43,30 @@ service.interceptors.response.use(
|
|
|
* You can also judge the status by HTTP Status Code
|
|
|
*/
|
|
|
response => {
|
|
|
- if (response.headers['content-type'] === 'image/jpeg') {
|
|
|
- return response.data
|
|
|
+ const res = response.data
|
|
|
+ // if the custom code is not 20000, it is judged as an error.
|
|
|
+ if (res.code === 200) {
|
|
|
+ return res
|
|
|
} else {
|
|
|
- const res = response.data
|
|
|
- // if the custom code is not 20000, it is judged as an error.
|
|
|
- if (res.code === 200) {
|
|
|
- return res
|
|
|
- } else {
|
|
|
+ Message({
|
|
|
+ message: res.msg || 'Error',
|
|
|
+ type: 'error',
|
|
|
+ duration: 5 * 1000
|
|
|
+ })
|
|
|
+
|
|
|
+ // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
|
+ if (res.code === 401) {
|
|
|
+ // to re-login
|
|
|
Message({
|
|
|
- message: res.msg || 'Error',
|
|
|
+ message: '请重新登录',
|
|
|
type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
+ duration: 3 * 1000
|
|
|
+ })
|
|
|
+ store.dispatch('user/resetToken').then(() => {
|
|
|
+ location.reload()
|
|
|
})
|
|
|
-
|
|
|
- // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
|
- if (res.code === 401) {
|
|
|
- // to re-login
|
|
|
- Message({
|
|
|
- message: '请重新登录',
|
|
|
- type: 'error',
|
|
|
- duration: 3 * 1000
|
|
|
- })
|
|
|
- store.dispatch('user/resetToken').then(() => {
|
|
|
- location.reload()
|
|
|
- })
|
|
|
- }
|
|
|
- return Promise.reject(new Error(res.msg || 'Error'))
|
|
|
}
|
|
|
+ return Promise.reject(new Error(res.msg || 'Error'))
|
|
|
}
|
|
|
},
|
|
|
error => {
|