12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import AxiosError from 'axios/lib/core/AxiosError';
- export default function ({ $axios, $auth, redirect }) {
- // $axios.defaults.dataKey = 'data';
- $axios.onRequest((config) => {
- config.headers.client = 7;
- return config;
- });
- $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);
- // if (response.data.status === 502) {
- // }
- 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;
- // }
- return response;
- });
- // $axios.onError((error) => {
- // const code = parseInt(error.response && error.response.status);
- // if (code === 400) {
- // redirect('/400');
- // }
- // });
- // globalThis.$axios = $axios;
- }
|