Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Subsequent Requests produces SyntaxError: "[object Object]" is not valid JSON React Query

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading