-
Notifications
You must be signed in to change notification settings - Fork 435
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
Feature Request: Ability to access fetch errors when the network or server is unreachable during GET requests #460
Comments
As of #424, Outside of that, would attaching listeners for |
#424 looks like it will work for my use case.
|
@corporealfunk you're correct in that. What I meant to share was the |
@seanpdoyle - I think As of right now, this does not fire on a network connection is lost for Visit using the following steps:
FYI, similar request in #460 |
I'm actually going to reopen this. My previous use case was satisfied with the merge of PR #424, but I have another use case now where Turbo doesn't seem to expose fetch error states like NetworkError: If I set a turbo frame's "src" attribute programmatically and the loading of that URL results in a NetworkError, there seems to be no way to intercept that error. #424 only deals with form submissions. Note that setting a turbo frame's src does result in some turbo events getting triggered (for example It'd be great to have a more global way of accessing any turbo-driven Fetch request that results in a NetworkError, not just for form submissions. We have them for Forms with |
@corporealfunk I'm curious, if you set |
If I deal with the
I'm not super familiar with Turbo internals, but here, we can see that the code that makes the fetchRequest creates a Promise that only calls resolve and never rejects: turbo/src/core/frames/frame_controller.ts Line 244 in b419c0d
And here, turbo/src/core/frames/frame_controller.ts Line 89 in b419c0d
Tracing further, the FetchRequest's perform method is called: turbo/src/http/fetch_request.ts Line 80 in b419c0d
When an error is caught in the promise chain, the delegate's turbo/src/http/fetch_request.ts Line 90 in b419c0d
and the error is re-thrown. In addition, the delegate's turbo/src/core/frames/frame_controller.ts Line 191 in b419c0d
So, it seems to resolve the promise even on error. |
In the case where a fetch request fails because the network or remote server is unreachable, a NetworkError is thrown and logged in the console (as well as the uncaught in promise error). If the fetch request was created because of a form POST, turbo:submit-end is also dispatched and developers can access the submit state and error message via the dispatched event.
However, other actions that may cause Turbo to create a fetch GET request that then fails because the network is unreachable (for example, programmatically setting a turbo frame src attribute, or using a form with GET instead of POST) do not dispatch any turbo:* events at all and developers do not have the ability to programmatically respond to the network error.
Could these types of failures always dispatch a turbo event, not just in the case of a form submission?
The text was updated successfully, but these errors were encountered: