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

feat: show correct error message for interval server errors #6873

Merged
merged 4 commits into from
Dec 20, 2023
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
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
Loading