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

Conversation

dacook
Copy link
Member

@dacook dacook commented Sep 17, 2024

I'm not sure why, but Turbo was swallowing the unauthorized error, so I thought we should alert the user to help with debugging. Same with network error, it gave no feedback before.

I think this can be tested with Capybara in theory, but I haven't invested the time on it.

What should we test?

This occurs whenever submitting a form with Turbo. The best example is running any report.

There are three types of errors:

  1. Network error: turn off wifi/disable network
  2. Authorisation error: This can be tested with bug Asking a report has no result when the producer is set as profile only (doesn't sell products) #12835. Otherwise I think you could test this by log out in another tab then log in as a shopper
  3. Other errors (eg 500). You could temporarily stop puma on the staging server: sudo systemctl stop puma (then start it again).

There are other types of errors that aren't handled by this and should be handled differently, for example:

  1. On the bulk product page, if you try to update a product that will fails we get a 422 that we handle nicely on the UI

@dacook dacook added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Sep 17, 2024
@dacook dacook self-assigned this Sep 17, 2024
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice one ! we could probably do something a bit nicer than using an alert but that's better than nothing. I hate it when error get swallowed.

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Actually it's causing issue on the bulk product page, if you try to update a product that will fails we get a 422 that we handle nicely on the UI. But with this change we now get an alert !

@dacook
Copy link
Member Author

dacook commented Sep 18, 2024

Oh, that makes sense, thanks for checking that out. It's worrying that the specs didn't pick that up!

@rioug
Copy link
Collaborator

rioug commented Sep 18, 2024

Oh, that makes sense, thanks for checking that out. It's worrying that the specs didn't pick that up!

I think the system specs accept alert by default if no behaviour specified.

@dacook dacook marked this pull request as draft November 4, 2024 02:28
if(status == 401) {
alert(I18n.t("errors.unauthorized.message"));
} else if(status === undefined) {
alert(I18n.t("errors.network_error.message"));
} else {
Copy link
Member Author

Choose a reason for hiding this comment

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

Looking at this again, I think we should not catch all 4xx (Client errors) with a generic message. They need specific handling and perhaps are handled differently in different parts of the app.

But we can catch all 5xx (server errors) and give a general message.

Suggested change
} else {
} else if (status >= 500) {

(I'm not sure if status is a string or integer, but it will be sorted correctly either way)

How does that sound to you @rioug?

Copy link
Member Author

Choose a reason for hiding this comment

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

I note that the existing frame-missing event handler would no longer cover the situation where an unexpected client error results in no turbo-frame response. But Gaetan already tested that a 422 is handled correctly, so it should be fine 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good 👍

I'm not sure why, but Turbo was swallowing the unauthorized error, so I thought we should alert the user to help with debugging.
Same with network error, it gave no feedback before.

I think this is testable in theory, but I haven't invested the time on it.
@dacook dacook force-pushed the turbo-error-messages branch from 32dac1a to a3a7968 Compare December 17, 2024 01:10
@dacook dacook added pr-staged-au staging.openfoodnetwork.org.au and removed pr-staged-au staging.openfoodnetwork.org.au labels Dec 17, 2024
@dacook dacook marked this pull request as ready for review December 17, 2024 02:56
@dacook
Copy link
Member Author

dacook commented Dec 17, 2024

Testing:

Network error ✅

Screenshot 2024-12-17 at 1 49 33 PM

Application error (422) ✅

Screenshot 2024-12-17 at 1 51 24 PM

Authentication error 🆇

Not as I hoped, because when logged out it returns a 302. We don't handle those (before or after this PR). Maybe next time...
Screenshot 2024-12-17 at 1 53 26 PM

Authorisation error (401) ✅

I achieved this by removing admin permission on my user.
Note that the alert appeared twice. But for an exception I think that's ok. The main thing is that the user got an explanation.
Screenshot 2024-12-17 at 2 01 31 PM

Server error (503) ✅

The alert appeared twice again.
Screenshot 2024-12-17 at 1 54 21 PM

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice one 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Test Ready 🧪
Development

Successfully merging this pull request may close these issues.

3 participants