I'm using react query to do a POST request. The request is successful the first time it executes, but keeps producing this error afterwards, even if the page refreshes. It also works if I clear cookies, but only once then the error keeps coming. This is the error message :
SyntaxError: "[object Object]" is not valid JSON
at JSON.parse (<anonymous>)
at AxiosClient.js:22:1
at async loginUser (user.api.js:7:1)
at async Mutation.execute (mutation.ts:200:1)
I have confirmed that in fact my POST body is not empty or undefined.
CodePudding user response:
It sounds like your POST request is returning an object instead of JSON, which is causing the error. Try parsing the response from your POST request before returning it to the caller.