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

Alert user when error requesting a report #12867

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions app/webpacker/js/turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ document.addEventListener("turbo:frame-missing", (event) => {
event.preventDefault();

// show error message instead
status = event.detail.response.status;
showError(event.detail.response?.status);
});

document.addEventListener("turbo:submit-end", (event) => {
if (!event.detail.success){
// show error message on failure
showError(event.detail.fetchResponse?.statusCode);
event.preventDefault();
}
});

function showError(status) {
// Note that other 4xx errors will be handled differently.
if(status == 401) {
alert(I18n.t("errors.unauthorized.message"));
} else {
} else if(status === undefined) {
alert(I18n.t("errors.network_error.message"));
} else if (status >= 500) {
alert(I18n.t("errors.general_error.message"));
}
});
}
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ en:
We record all errors and may be working on a fix.

If the problem persists or is urgent, please contact us."
unauthorized:
message: "You are not authorised to perform that action."
network_error:
message: "Network error: please try again later."
stripe:
error_code:
incorrect_number: "The card number is incorrect."
Expand Down
Loading