Skip to content

Commit

Permalink
修改axios模板
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojun committed Jul 15, 2020
1 parent f0676b0 commit b66d1cd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/cra-template-4pd/template/src/api/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const instance = axios.create({
baseURL: '',
});

instance.interceptors.request.use((config) => {
instance.interceptors.request.use(config => {
if (config.method === 'get') {
if (!config.params) {
config.params = {};
Expand All @@ -15,17 +15,18 @@ instance.interceptors.request.use((config) => {
return config;
});
instance.interceptors.response.use(
(response) => {
response => {
const { status, error } = response.data;
if (status !== '0') {
message.error(`code:${error}`);
return Promise.reject(error);
}
return response.data;
},
(error) => {
message.error(error.toString());
return Promise.reject(error.toString());
error => {
const errorMsg = error.response.data?.msg || error.toString();
message.error(errorMsg);
return Promise.reject(error);
},
);

Expand Down

0 comments on commit b66d1cd

Please sign in to comment.