-
Hi everybody, I'm currently enjoying RTK Query a lot, and I think the provided documentation is great. However, I could not find the answer to one of my needs: validation, and where to put it. The point is: when the server returns a 200:OK status response with a body (e.g.: I requested a Pokemon), I "don't trust" the server and would like to validate the response body against some custom rules (for example, check that the pokemon name is there etc.) and throw a custom error to let the rest of my code know that something is wrong. If I try to use the
This is rather scary, so: where should I put my validation? Sample here: https://codesandbox.io/s/nervous-field-64vr6 Thanks in advance to anyone who'd like to give me an answer! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Based on the docs, one way of handling this would be to use the queryFn method that returns an object with either a |
Beta Was this translation helpful? Give feedback.
Based on the docs, one way of handling this would be to use the queryFn method that returns an object with either a
data
field if the response is ok, or anerror
field if the response is invalid. But perhaps there exists something even more idiomatic?