123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 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;
- }
|