Selector for rejected promises
Hi, is there a way to select and transform the body from an error response,
If I get this from the API:
{ result: null, error: { message: "something is wrong" } }
and I want to select the error object from the response (so the react query error object would be just { message: "something is wrong" }), I know we can pass a select callback to transform the result when the promise success, but I don't see something like that for rejected promises.3 Replies
like-gold•4y ago
Hi you can catch the error in the queryFn and throw a new one with the expected shape.
wise-whiteOP•4y ago
Yes that's what I am doing
But it may be handy to have a errorSelector if we have a selector for successful promises
other-emerald•4y ago
The selector for the success result lets you subscribe to parts of the query cache. That's not needed for errors