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

[Fix] Handled client side network issues #833

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions frontend/src/hooks/useExceptionHandler.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ const useExceptionHandler = () => {
duration: duration,
};
}
if (err.code === "ERR_NETWORK" && !navigator.onLine) {
return {
type: "error",
content: "Please check your internet connection.",
title: title,
duration: duration,
};
} else if (err.code === "ERR_CANCELED") {
return {
type: "error",
content: "Request has been canceled.",
title: title,
duration: duration,
};
}
Comment on lines +21 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (err.code === "ERR_NETWORK" && !navigator.onLine) {
return {
type: "error",
content: "Please check your internet connection.",
title: title,
duration: duration,
};
} else if (err.code === "ERR_CANCELED") {
return {
type: "error",
content: "Request has been canceled.",
title: title,
duration: duration,
};
}
const getErrorMessage = (err, title, duration) => {
const errorMessages = {
ERR_NETWORK: "Please check your internet connection.",
ERR_CANCELED: "Request has been canceled.",
};
if (errorMessages[err.code]) {
return {
type: "error",
content: err.code === "ERR_NETWORK" && !navigator.onLine ? errorMessages.ERR_NETWORK : errorMessages[err.code],
title,
duration,
};
}
return null; // or handle other error cases
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check and apply this change if seems okay. @jagadeeswaran-zipstack

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this can be used because adding more error codes will make the content condition more complicated. If you think otherwise please let me know.


if (err?.response?.data) {
const { type, errors } = err.response.data;
Expand Down