Probably shouldn’t give a 500 - that suggests an oversight in Companies House code.
For what it’s worth that’s not simply a “non-existent” company, it’s a completely invalid number. All things in their registry have an 8 character “number”. Presumably somewhere in their software has that as an assumption?
Playing around here, there are at least 3 cases. Feeding these in to the “company profile” endpoint e.g. with curl -I -X GET -u API_KEY_HERE: "https://api.company-information.service.gov.uk/company/NF004299"
Valid company number: NF004299 - this gives a 200 response and the expected JSON body.
Non-existent (but not completely invalid) company number: 99999999
This gives a 404 and the error body:
{
"errors": [
{
"type": "ch:service",
"error": "company-profile-not-found"
}
]
}
Invalid CH number (one extra character): 999999999
As you say this gives a 500 and the body:
{
"exception_id": "6wm4ym5vfxu3",
"error": "Internal server error"
}