42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import axiosConfig from "./axios_config";
|
|
import axios from 'axios';
|
|
|
|
const service = axios.create(axiosConfig);
|
|
|
|
// 请求拦截
|
|
service.interceptors.request.use(
|
|
config => {
|
|
// (config.headers as any).Authorization = 'Bearer' + ' ' + store.getState().chatgpt.token;
|
|
// if (config.data) {
|
|
// config.data = JSON.stringify(config.data);
|
|
// };
|
|
// if (config.method?.toLocaleLowerCase() === 'get') {
|
|
// config.paramsSerializer = function (params) {
|
|
// return qs.stringify(params, { arrayFormat: 'repeat' })
|
|
// }
|
|
// };
|
|
return config;
|
|
},
|
|
( error: any) => {
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
// 响应拦截
|
|
service.interceptors.response.use(
|
|
(res: any) => {
|
|
// let data = JSON.parse(res.data);
|
|
let data = res.data;
|
|
console.log(data)
|
|
return data;
|
|
},
|
|
( error: { response: { data: string; }; }) => {
|
|
let data = JSON.parse(error.response.data);
|
|
// if (data.code === 500) {
|
|
// console.log(error)
|
|
// };
|
|
return data
|
|
}
|
|
)
|
|
|
|
export default service; |