#if 404 not found empty response but react query still showing old data

26 messages · Page 1 of 1 (latest)

brave kelp
#

<@&763868191163940874>

brazen estuary
#

Does your queryFn return undefined when you 404?

brazen estuary
#

I'm not sure that helps. Idk what response.data could be or if you even reach there in an error. My initial hunch was you were returning undefined which doesn't work, it has to use null (it should warn you)

brave kelp
#

@brazen estuary so the api response is this and 404 status. I am console loging response.data and it's showing the old data from 200 status

brazen estuary
#

You put that console.log in that getTraderStrageties function before the return?

brave kelp
#

yeah here

brazen estuary
#

This sounds like something is fishy with your API server/client code

#

If you get the old data there that's not any doing of RQ

brave kelp
#

api is fine giving correct response. maybe axios problem!

#

I think need to put try catch inside my getTraderStrategies hmm

#

and return null on catch

brazen estuary
#

Not sure you're even throwing an error to catch based on what you're saying

#

If you get to the console.log after the get() call to axios, then it sounds like it didn't error

brave kelp
#

if I reload the page it's goes away and work. but not real time

#

lol it's working after putting the try catch

#

ig axios problem

brazen estuary
#

Well at least that's progress, sorry I wasn't more help

brave kelp
#

@brazen estuary instade of returning null is there any promise I can return that also works

#

ig undefined dosen't work

brazen estuary
#

Yeah you can't return undefined from a queryFn. You either need to return null or throw an Error

brave kelp
#

k

#

return Promise.resolve(null)
this worked

#

thanks @brazen estuary