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

This commit is contained in:
Vben 2024-10-18 22:00:41 +08:00 committed by GitHub
parent 6f3d50984f
commit 240f0b5f8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 19 additions and 12 deletions

View File

@ -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;
},
});

View File

@ -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;
},
});

View File

@ -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;
},
});

View File

@ -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;
},
});

View File

@ -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;
},
});

View File

@ -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;
},
});