cc'ing Jersey mailing list as it might be related directly to Jersey,
not Grizzly.
Thanks.
WBR,
Alexey.
On 26.06.14 00:03, Ramesh.Kanesan_at_ubs.com wrote:
>
> Hi,
>
> I've implemented an ExceptionMapper as follows, however Grizzly just
> displays the prettified "Internal Server Error" message instead of the
> json. If I change the response to Status.OK I can see the JSON just
> fine, any ideas on how to get Grizzly to the same for
> Status.INTERNAL_SERVER_ERROR?
>
> Any help is much appreciated.
>
> Kind Regards,
>
> -Ramesh
>
> @Provider
>
> public class UnexpectedExceptionMapper implements
> ExceptionMapper<Exception> {
>
> private final CustomJacksonObjectMapper customJacksonObjectMapper
> = new CustomJacksonObjectMapper();
>
> @Override
>
> public Response toResponse(Exception exception) {
>
> return Response.status(Status.INTERNAL_SERVER_ERROR)
>
> .entity(convertToJson(exception))
>
> .type(MediaType.APPLICATION_JSON)
>
> .build();
>
> }
>
> private String convertToJson(Exception exception) {
>
> try {
>
> return customJacksonObjectMapper.writeValueAsString(new
> ErrorInfo(exception.getMessage()));
>
> } catch (JsonProcessingException e) {
>
> return "{\"errorMessage\":\"An internal error occurred\"}";
>
> }
>
> }
>
> }
>