reactjs - PHP backend sometimes return status code 500 with HTML, how can my react front end handle this?
one text
Solution:
Response, even an error response, should contain Content-Type
header which in your case should be either application/json
for JSON responses and text/html
for HTML responses. You should always only JSON-decode responses with application/json
content type. Actually axios will do that for you if a proper content type header is present on the response.
There's a chance though that your API is returning JSON with text/html
content type. If that happens, you have to have some serious discussion with your backend developers and strongly insist on having proper Content-Type
on all API responses.