request.ts
860 Bytes
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
import axios from 'axios';
import { message as $message } from 'antd';
const Service = axios.create({
baseURL: '/api',
timeout: 20000,
});
Service.interceptors.request.use(
config => {
const aToken = sessionStorage.getItem('aToken') || 'bearer fff06119-e69f-4527-a4bc-d4ca613e09be';
aToken && (config.headers.Authorization = aToken);
return config;
},
error => {
Promise.reject(error);
}
);
Service.interceptors.response.use(
(response: any) => {
const res = response.data;
if (res.code === 0 || res.success) {
return Promise.resolve(res);
} else {
// if (res.code === 400 || res.code === 401) {
$message.error(res.message);
// return
// } else {
return Promise.reject(res.message);
// }
}
},
error => {
Promise.reject(error);
}
);
export default Service;