Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP 500 Response with Body?

I have a RESTEasy service that returns a HTTP 500 when a server side error occurs. I manage to attach a body to the HTTP response in order to give more details about the error. So the response that comes out of the service looks something like this

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: application/xml;charset=ISO-8859-1
Content-Language: en-US
Content-Length: 3251
Date: Thu, 14 Oct 2010 23:22:49 GMT
Connection: close

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><myErrorEnvelope><internalCode>123</internalCode><description>error details</description></myErrorEnvelope>

I have a client (spring MVC 3.0 REST client) and I am trying to capture the HTTP 500 and read the body of the response and deserialize the myErrorEnvelope object. I first catch a catch RestClientException and it correctly tells me there was a HTTP 500 response but then there seems to be no way to get the Body of the response. Is this something I'm not supposed to be able to do? Am I supposed to return the error object as the body of a HTTP 200 response instead? I really would rather return HTTP 500 with a body.

Thanks.

like image 367
pastafarian Avatar asked Oct 14 '10 23:10

pastafarian


People also ask

What does a 500 HTTP response indicate?

The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. This error response is a generic "catch-all" response.

Is it OK to return 500?

Never return 500 errors intentionally. The only type of errors you should be showing to the user intentionally is validation (400) errors. 500 codes are all about something you don't anticipate to happen.


1 Answers

You're trying to do the right thing. A framework that doesn't let you get the payload of a non-2xx response simply is broken.

like image 154
Julian Reschke Avatar answered Nov 09 '22 08:11

Julian Reschke