带正文的HTTP 500响应? [英] HTTP 500 Response with Body?

查看:119
本文介绍了带正文的HTTP 500响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RESTEasy服务,该服务在发生服务器端错误时返回HTTP 500.我设法将主体附加到HTTP响应,以便提供有关该错误的更多详细信息.因此,来自服务的响应看起来像这样

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>

我有一个客户端(Spring MVC 3.0 REST客户端),我试图捕获HTTP 500并读取响应的正文并反序列化 myErrorEnvelope 对象.我首先捕获了一个捕获 RestClientException ,它正确地告诉我存在HTTP 500响应,但是随后似乎没有办法获取响应的主体.这是我不应该做的吗?我是否应该将错误对象作为HTTP 200响应的正文返回?我真的希望返回带有正文的HTTP 500.

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.

谢谢.

推荐答案

您正在尝试做正确的事情.不允许您获取非2xx响应的有效负载的框架被破坏了.

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.

这篇关于带正文的HTTP 500响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆