1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import axios from 'axios';
import { Notify } from 'quasar';
import appConfig from 'src/config/app';
const $axios = axios.create();
// 请求方法
const request = (options: any) => {
const defaultOptins = {
baseURL: appConfig.base_url,
timeout: 30000,
};
const config = Object.assign(defaultOptins, options);
return $axios(config);
};
// http request 拦截器
$axios.interceptors.request.use(
(config: any) => {
return config;
},
(error) => {
return Promise.reject(error);
}
);
// http response 拦截器
$axios.interceptors.response.use(
(response: any) => {
return response;
},
async (error) => {
let msg = 'Unknown Error';
if (error.response.status === 500 || error.response.status === 504) {
msg = 'Internal Server Error';
} else {
msg = error.response.data.detail.msg; // 接口返回的错误信息
}
Notify.create({
message: msg,
type: 'negative',
position: 'top-right',
});
return Promise.reject(error);
}
);
export default request;