"Unexpected token <" error indicates API returning HTML instead of JSON
The 'Unexpected token <' error in JavaScript occurs when a parser expecting JSON data receives an HTML document from an API endpoint. This commonly happens when servers return error pages like 404 or 500 statuses, or when single-page app fallbacks serve index.html for unmatched paths. The issue can also stem from redirects to login pages due to expired sessions, or from security tools like WAFs and proxies serving HTML interstitials. Developers can diagnose the problem by checking response headers and the first few bytes of the body before parsing.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in