Replies: 3 comments 4 replies
-
I guess you can catch it inside the loader or action. export const loader = () => {
try {
...
} catch (e) {
return json({ error: e })
}
} But I agree with you, it shouldn't break any existing apps. and the submission feedback could be more easier. |
Beta Was this translation helpful? Give feedback.
-
possible (hacky) solution: add a service worker that intercepts all your traffic and then returns an error object so you can have: const fetcher = useFetcher()
fetcher.data.response // your actual response (could be null)
fetcher.data.error // the error object returned by the service worker (when response is null) |
Beta Was this translation helpful? Give feedback.
-
Related React Router proposal: remix-run/react-router#10013. We should probably prefer that one since that's where the fetcher code lives nowadays. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When using
fetcher.load
orfetcher.submit
, Remix handles any uncaught errors and renders an error boundary. It would be nice to override this error handling when needed. The useFetcher documentation says "Handles uncaught errors by rendering the nearest", but as far as I can tell, all errors are uncaught since there is no way currently to catch useFetcher errors.In my use case, we have some fetchers that run in the background to automatically submit some application state to the server a couple times per minute. If anything happens between the client and server to throw an error (most common seems to be a Failed to Fetch error due to be their wifi dropping out momentarily during a
fetcher.submit
call), the whole page falls back to an error boundary. For now we're just using a plainfetch(...)
instead of useFetcher to work around this, but then we lose the data reloading capabilities of Remix. It would be great to have access to the error when needed and decide if I want to handle it myself or let Remix render the error boundary.The options below would generally be opt-in, so it shouldn't break any existing apps. Option 1 would change the return type of
load
andsubmit
, but you would still be able to use them the same way as before. Leaving out the error handling in each portion would just have Remix render the error boundary like does now.Option 1: Promises
Have
load
andsubmit
return promises that can be caught. The added benefit would be the ability to add.then(() => { ... })
handlers when the request is complete (there are several discussion threads about that already). I'm not sure how well this would work with Remix's current fetcher implementation though.Option 2: Callbacks
Add an optional onError callback to
SubmitOptions
for error handling. If this option is present, Remix would call that method instead of the internalmaybeBailOnError
, and then set the fetcher state to something like{state: "idle", type: "error", error: error}
(or settingdata
to the error)Option 3: Adding flag to options
Similar to Option 2, add
showErrorBoundary?: boolean
toSubmitOptions
for error handling. If this option is present, Remix will skip calling the internalmaybeBailOnError
, and then set the fetcher state to something like{state: "idle", type: "error", error: error}
(or settingdata
to the error)Beta Was this translation helpful? Give feedback.
All reactions