u/PrevAccLocked

How do you handle error with rxResource

Hello,

Since we upgraded from v19 to v22, our way of handling errors with rxResource for http requests seem to be the wrong way of doing it.

Basically we have a helper method that will display log the thrown error and a toast for the user, this method returns a EMPTY observable for rxjs, so a rxResource looks like this:

public readonly resource = rxResource({
  params: () => ({ id: this.id() }),
  loader: ({ params: request }) =>
    this.query.getInfo(request.id).pipe(
      catchError((err) => {
        return this.error.onLoadErrorHandler(err); // this is the method that returns EMPTY
      }),
    ),
});

But now, since the change in rxResource with the stream parameter it seems that you should no longer do it as it throws and error, my understanding is that this error comes the EMPTY. I cannot provide the error right now, apologies.

I understand that httpResource exist but we didn't want to use them for now.

So should we create an effect for every resource to listen to resource.error() and call this helper method to handle the error? Not a big fan of this as it will separate the resource declaration and its error handling. One way to prevent this would be to create a wrapper around resource that both creates the resource and the effect but I'm not sure if this is the right idea.

How do you guys handle error handling for this use case ?

reddit.com
u/PrevAccLocked — 8 days ago