123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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) => {
- // console.log("🚀 ~ file: axios.js ~ line 11 ~ $axios.onResponse ~ response", response)
- if (Object.prototype.toString.call(response.data) === '[object Object]') {
- if ([6013, 6014].includes(response.data.status)) {
- // await $auth.logout();
- await $auth.reset();
- // 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;
- }
|