Use valid JSON for error responses

Currently, the error response is not valid JSON. 
I haven't written a test as it is guarded behind the `Endpoint.production?` check.