#Any approach to identify errors using defer + Await?

1 messages · Page 1 of 1 (latest)

hoary trench
#

I'm currently working on a loader function that streams the response using defer. I use <Await resolve={promise} errorElement={<SomeError />} to show a generic error, but I want to be able to show different messages depending on the error.

The docs say that inside your error element, you can access the error with the useAsyncError() hook, but in production, Remix sanitizes the errors, stripping out all the data. This means that I can't really get any information from the error and I'm stuck showing a generic message every time an defered response fails, no matter the error.

The best I could come up with was wrapping my promise with a withAsyncError function that returns and optional error field that I can use inside the Await component to show a custom error message. But I feel there could be another way to avoid using the "happy path" inside the Await children as a way to show errors.

Is there a better way to work around this limitation? Possibly leveraging the errorElement or ErrorBoundary features?

grizzled lotus
#

Hello @hoary trench did u find a better way to do this