400, 401, 403, and 404 errors are JSON too, but 500 and requests to a non-existent path come as an HTML page. So check the status code and the Content-Type header first, and only then parse the body.
API response codes and what to do about them.
400, 401, 403, and 404 errors are JSON too, but 500 and requests to a non-existent path come as an HTML page. So check the status code and the Content-Type header first, and only then parse the body.