|
From: Roman <rom...@gm...> - 2010-04-07 05:48:41
|
Hello,
In my RESTEasy client application I would like to be able to retrieve
the response body when server responds with 500 error code, in order
to provide a meaningful error message to the user. Attempt to read the body
from exception using the following code fails, as the input
stream is already closed:
ClientResponse response = failure.getResponse();
responseBody = (String) response.getEntity(String.class);
I'was able to work around it by creating a ClientErrorInterceptor
which does nothing, but reads the response body as
public void handle(ClientResponse<?> response) throws RuntimeException {
try {
response.getEntity(String.class);
} catch (Exception e) {
e.printStackTrace();
}
}
The above exception handling code started working after that.
Still, it works only in some clients, others fail to read response
body. I do not have an exact error message at hand, but it is saying
something like "MessageBodyReader for media type */* and Java type
java.lang.String is not found".
Am I missing some bits in the solution or Is there any better way to
solve the problem?
Thank you,
Roman
|