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

HTTP Error handling policy across Gutenberg #39254

Open
adamziel opened this issue Mar 7, 2022 · 2 comments
Open

HTTP Error handling policy across Gutenberg #39254

adamziel opened this issue Mar 7, 2022 · 2 comments
Labels
[Package] API fetch /packages/api-fetch REST API Interaction Related to REST API [Type] Enhancement A suggestion for improvement.

Comments

@adamziel
Copy link
Contributor

adamziel commented Mar 7, 2022

Right now, there is no standardized way of handling HTTP errors in Gutenberg.

Any request may fail for a number of reasons, and different errors require different handling. Sometimes, the error is up to a specific API consumer to handle, for example:

  • When a resolver re-requests an entity record that is now missing, it would make sense to remove it from the state and ensure it is somehow communicated to the user.
  • When the validation failed, it would be great to tell the user why.

But there is also a class of global errors that could be consistently handled whenever they occur in random actions or resolvers, for example:

  • When the user is no longer authenticated, it would be great to display a login form.
  • When the user is unauthorized to do something, it would be great to tell them, and perhaps refresh the page if their permissions changed while the editor was open.
  • When the server had a temporary hiccup, it would be great to retry the request before failing.
  • Ditto for temporary network connection issues.

These are merely examples to illustrate the problem. There are many, many more scenarios and the list of HTTP response error codes would be a good place to start mapping out different cases so that we could discuss the most appropriate behaviors.

Related reads:

cc @youknowriad @jsnajdr @Mamaduka @dmsnell @gwwar @ntsekouras @jorgefilipecosta @ellatrix @gziolo @draganescu @scruffian @getdave @paaljoachim @spacedmonkey @TimothyBJacobs @talldan @noisysocks @kevin940726

@noisysocks
Copy link
Member

noisysocks commented Mar 7, 2022

When the user is no longer authenticated, it would be great to display a login form.

I think the block editor uses the same "heartbeat" mechanism as the rest of WP Admin and should show a login form if the session has expired. Perhaps could look at extending that if it's not enough.

When the user is unauthorized to do something, it would be great to tell them, and perhaps refresh the page if their permissions changed while the editor was open.

Let's just be careful about not losing any of the user's unsaved content during this.

When the server had a temporary hiccup, it would be great to retry the request before failing.
Ditto for temporary network connection issues.

I'm not sure about retrying automatically. Usually when I encounter network connection issues it's because I'm passing through a tunnel on my phone or not connected to WiFi. In these cases I want to retry the operation after I fix the issue. Could we show a Retry button on a Connection issue toast notification?

@getdave
Copy link
Contributor

getdave commented Mar 8, 2022

I wonder what we could learn from https://react-query.tanstack.com/guides/query-retries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] API fetch /packages/api-fetch REST API Interaction Related to REST API [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants