|
@@ -1,32 +1,39 @@
|
|
|
import AxiosError from 'axios/lib/core/AxiosError';
|
|
|
|
|
|
-export default function ({ $axios, redirect }) {
|
|
|
+export default function ({ $axios, $auth, redirect }) {
|
|
|
// $axios.defaults.dataKey = 'data';
|
|
|
|
|
|
$axios.onRequest((config) => {
|
|
|
config.headers.client = 7;
|
|
|
return config;
|
|
|
});
|
|
|
- $axios.onResponse((response) => {
|
|
|
- if (response.data.status !== 0) {
|
|
|
- // const err = new Error(
|
|
|
- // response.data.msg || response.data.data || '未知错误',
|
|
|
- // );
|
|
|
- // Object.assign(err, response);
|
|
|
+ $axios.onResponse(async (response) => {
|
|
|
+ if (Object.prototype.toString.call(response.data) === '[object Object]') {
|
|
|
+ if ([2, 4, 6013, 6014].includes(response.data.status)) {
|
|
|
+ await $auth.logout();
|
|
|
+ // await $auth.setUserToken(null);
|
|
|
+ }
|
|
|
+ if (response.data.status !== 0) {
|
|
|
+ // const err = new Error(
|
|
|
+ // response.data.msg || response.data.data || '未知错误',
|
|
|
+ // );
|
|
|
+ // Object.assign(err, response);
|
|
|
|
|
|
- // return Promise.reject(err);
|
|
|
+ // return Promise.reject(err);
|
|
|
|
|
|
- // if (response.data.status === 502) {
|
|
|
- // }
|
|
|
+ // if (response.data.status === 502) {
|
|
|
+ // }
|
|
|
|
|
|
- throw new AxiosError(
|
|
|
- response.data.msg || response.data.data || '未知错误',
|
|
|
- null,
|
|
|
- response.config,
|
|
|
- response.request,
|
|
|
- response,
|
|
|
- );
|
|
|
+ throw new AxiosError(
|
|
|
+ response.data.msg || response.data.data || '未知错误',
|
|
|
+ null,
|
|
|
+ response.config,
|
|
|
+ response.request,
|
|
|
+ response,
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
// else if (response.config.dataKey) {
|
|
|
// response.data = response.data[response.config.dataKey];
|
|
|
// return response;
|