Skip to content

Commit

Permalink
feat: show correct error message for interval server errors (#6873)
Browse files Browse the repository at this point in the history
* feat: show correct error message for interval server errors

* modify handleResponse.ts
  • Loading branch information
jainvedant392 authored Dec 20, 2023
1 parent 4c08326 commit dc6d049
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
30 changes: 3 additions & 27 deletions src/Redux/fireRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const fireRequest = (
}

// 4xx Errors
if (error.response.status > 400 && error.response.status < 500) {
if (error.response.status > 400 && error.response.status < 600) {
if (error.response.data && error.response.data.detail) {
if (error.response.data.code === "token_not_valid") {
window.location.href = `/session-expired?redirect=${window.location.href}`;
Expand All @@ -167,14 +167,6 @@ export const fireRequest = (
}
return;
}

// 5xx Errors
if (error.response.status >= 500 && error.response.status <= 599) {
Notification.Error({
msg: "Something went wrong...!",
});
return;
}
} else {
return error.response;
}
Expand Down Expand Up @@ -264,7 +256,7 @@ export const fireRequestV2 = (
}

// 4xx Errors
if (error.response.status > 400 && error.response.status < 500) {
if (error.response.status > 400 && error.response.status < 600) {
if (error.response.data && error.response.data.detail) {
Notification.Error({
msg: error.response.data.detail,
Expand All @@ -279,14 +271,6 @@ export const fireRequestV2 = (
}
return;
}

// 5xx Errors
if (error.response.status >= 500 && error.response.status <= 599) {
Notification.Error({
msg: "Something went wrong...!",
});
return;
}
}
});
};
Expand Down Expand Up @@ -374,7 +358,7 @@ export const fireRequestForFiles = (
}

// 4xx Errors
if (error.response.status > 400 && error.response.status < 500) {
if (error.response.status > 400 && error.response.status < 600) {
if (error.response.status === 429) {
return error.response;
} else if (error.response.data && error.response.data.detail) {
Expand All @@ -388,14 +372,6 @@ export const fireRequestForFiles = (
}
return;
}

// 5xx Errors
if (error.response.status >= 500 && error.response.status <= 599) {
Notification.Error({
msg: "Something went wrong...!",
});
return;
}
}
});
};
Expand Down
11 changes: 2 additions & 9 deletions src/Utils/request/handleResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ export default function handleResponse(
return;
}

// 5xx errors
if (res.status >= 500 && res.status < 600) {
console.error("Server error", res);
notify?.Error({ msg: "Something went wrong...!" });
return;
}

// 400/406 Bad Request
if (res.status === 400 || res.status === 406) {
notify?.BadRequest({ errs: error });
return;
}

// Other 400 Errors
if (res.status >= 400) {
// Other Errors between 400-599 (inclusive)
if (res.status >= 400 && res.status < 600) {
// Invalid token
if (!silent && error?.code === "token_not_valid") {
navigate(`/session-expired?redirect=${window.location.href}`);
Expand Down

0 comments on commit dc6d049

Please sign in to comment.