import AxiosError from 'axios/lib/core/AxiosError'; export default function ({ $axios, 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); // 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; }