Html Errors shown for JSON requests

We are using the beta API to search for companies by company number. the call is to a JSON document endpoint eg: Error Page (note the .json) however the 404 response is HTML and is a 200 response.

       <span class="errortitle">Request Failure</span>
      
       <strong>The following FAILURE message was generated:</strong><br/><br/>
       <span class="error">
              company number invalid
              <br>Error Code: 404
              <br/>				
	</span>

I would expect a 404 status code as the company does not exist and a JSON document not an HTML one. Something like:

{
     "result" : "failed",
      "code" : 404,
      "error" : "company number invalid"
}

That is not our Beta API, that is our legacy URI service.
Please visit https://developer.companieshouse.gov.uk/api/docs/ for information on using our Beta API

Ah so it is you are right. Thanks for the reply

As MArkWilliams said.

However I also use the URI service (e.g. when data has “disappeared” from the API data set) so if you find out who could fix this I’d be interested in it working as you’d expect.

What I found when I tested:

Data type is normally set via content negotiation (as documented at https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/426891/uniformResourceIdentifiersCustomerGuide.pdf). So (e.g. using curl):

curl --header “Accept: application/json” “URI
…returns json formatted response, and
curl --header “Accept: application/xml” “URI
…returns XML

Adding the appropriate file extension to the company number also does this as you say e.g. http://data.companieshouse.gov.uk/doc/company/SC002180.csv

Whichever method to specify format it seems you get HTML back if there’s an error.

I tried this for different error types:

I also tried content negotiation but was always returned as text/html regardless of what Accept headers are used. I do consider this behaviour a bug but as MArkWilliams not one related to the beta service.