mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge pull request #12867 from dacook/turbo-error-messages
Alert user when error requesting a report
This commit is contained in:
@@ -8,10 +8,24 @@ document.addEventListener("turbo:frame-missing", (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
// show error message instead
|
||||
status = event.detail.response.status;
|
||||
if(status == 401) {
|
||||
alert(I18n.t("errors.unauthorized.message"));
|
||||
} else {
|
||||
alert(I18n.t("errors.general_error.message"));
|
||||
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 if(status === undefined) {
|
||||
alert(I18n.t("errors.network_error.message"));
|
||||
} else if (status >= 500) {
|
||||
alert(I18n.t("errors.general_error.message"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user