Skip to content

Commit

Permalink
refactor: 重新改变拦截器返回的数据结构
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqinke committed Jan 21, 2024
1 parent 432d1cb commit 3721f11
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions src/api/axios-interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,17 @@ const resp415 = {
}
};

const resp20401 = {
onFulfilled(response) {
if (response.status === 200 && response.data.code === 20401) {
// 为了处理返回数据为空,hash
// $message.error({
// content: '获取到0条数据',
// duration: 1
// });
}
if (response.status === 200 && response.data.code === 41701) {
message.error({
content: "查询参数错误",
duration: 1
});
}
if (response.data.code !== 200 && response.data.message) {
message.error({
content: `${response.data.message}`,
duration: 1
});
}
return response;
const respTransform = {
onFulfilled({ data = {} }) {
// 改变数据结构,
return data;
}
};

const resperror = {
onRejected(error) {
message.error({
content: "请求错误",
content: "网络错误",
duration: 1
});
return Promise.reject(error);
Expand Down Expand Up @@ -131,4 +113,4 @@ const reqCommon = {

export const requestInterce = [reqCommon]; // 请求拦截

export const responseInterce = [resp401, resp403, resp404, resp415, resp20401, resperror]; // 响应拦截
export const responseInterce = [resp401, resp403, resp404, resp415, respTransform, resperror]; // 响应拦截

0 comments on commit 3721f11

Please sign in to comment.