T
TanStack2y ago
sensitive-blue

best way to handle errors of api that returns status 200 w error field

Is there a better way than an if / else condition onSuccess if your API returns 200 for errors ? my api returns always a 200 with fields { data, errors } and I would love to be able to get the errors in the onError() method
4 Replies
reduced-jade
reduced-jade2y ago
return data field and throw errors field in queryFn?
sensitive-blue
sensitive-blueOP2y ago
yup but that would make me add this for every queryFn so i would end up w a lot of extra code. I am looking for a generic solution which I think I found modifying the querycache on success at the client level
stormy-gold
stormy-gold2y ago
onSuccess on the queryCache + throw there could work
sensitive-blue
sensitive-blueOP2y ago
yup, thats what i did 👏 This is pretty handy since unfortunately stuff like graphql will always return 200

Did you find this page helpful?