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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With