Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improved exception handling when request status code is 200 #4679

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apps/web-antd/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ function createRequestClient(baseURL: string) {
fulfilled: (response) => {
const { data: responseData, status } = response;

const { code, data, message: msg } = responseData;
const { code, data } = responseData;
if (status >= 200 && status < 400 && code === 0) {
return data;
}
throw new Error(`Error ${status}: ${msg}`);

const error = { response };
throw error;
},
});

Expand Down
5 changes: 3 additions & 2 deletions apps/web-ele/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ function createRequestClient(baseURL: string) {
fulfilled: (response) => {
const { data: responseData, status } = response;

const { code, data, message: msg } = responseData;
const { code, data } = responseData;
if (status >= 200 && status < 400 && code === 0) {
return data;
}
throw new Error(`Error ${status}: ${msg}`);
const error = { response };
throw error;
},
});

Expand Down
5 changes: 3 additions & 2 deletions apps/web-naive/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ function createRequestClient(baseURL: string) {
fulfilled: (response) => {
const { data: responseData, status } = response;

const { code, data, message: msg } = responseData;
const { code, data } = responseData;
if (status >= 200 && status < 400 && code === 0) {
return data;
}
throw new Error(`Error ${status}: ${msg}`);
const error = { response };
throw error;
},
});

Expand Down
5 changes: 3 additions & 2 deletions docs/src/en/guide/essentials/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ function createRequestClient(baseURL: string) {
fulfilled: (response) => {
const { data: responseData, status } = response;

const { code, data, message: msg } = responseData;
const { code, data } = responseData;

if (status >= 200 && status < 400 && code === 0) {
return data;
}
throw new Error(`Error ${status}: ${msg}`);
const error = { response };
throw error;
},
});

Expand Down
5 changes: 3 additions & 2 deletions docs/src/guide/essentials/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@ function createRequestClient(baseURL: string) {
fulfilled: (response) => {
const { data: responseData, status } = response;

const { code, data, message: msg } = responseData;
const { code, data } = responseData;

if (status >= 200 && status < 400 && code === 0) {
return data;
}
throw new Error(`Error ${status}: ${msg}`);
const error = { response };
throw error;
anncwb marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand Down
5 changes: 3 additions & 2 deletions playground/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ function createRequestClient(baseURL: string) {
fulfilled: (response) => {
const { data: responseData, status } = response;

const { code, data, message: msg } = responseData;
const { code, data } = responseData;

if (status >= 200 && status < 400 && code === 0) {
return data;
}
throw new Error(`Error ${status}: ${msg}`);
const error = { response };
throw error;
},
});

Expand Down