
So, you thought you ordered mac and cheese but the server places a bowl of nachos in front of you. It’s the same story with APIs. Like cases where an API returned an HTML error page instead of the JSON you expected, causing your code to self-combust.
As mentioned above, this is often due to not specifying ‘Accept’ header with the request and the API not being sure what response format your code is expecting. On the provider side, many frameworks and web servers default to HTML, so if you’re creating an API that has no good reason for dishing up HTML, always make sure to check the default error response.
Other complicating factors might have nothing to do with your API, but be the result of software sitting in front (e.g. load balancers). If for example, an nginx instance encounters a request time-out, it can return an HTML error page by default before your API ever gets the chance to determine what’s cooking.
Download the Full Whitepaper