DefaultExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(Exception exception) { String message = exception.getMessage(); if (message == null) { message = exception.getClass().getName(); } return Response .status(500) .entity(message) .type(MediaType.TEXT_PLAIN) .header(ExtHttpHeaders.JAXRS_BODY_PROVIDED, "Error-Message") .build(); }  @Override Response toResponse(Exception exception);  }
@Test public void createsResponseWithStatus500AndUsesExceptionMessageAsEntity() { Exception exception = new Exception("<error message>"); Response response = exceptionMapper.toResponse(exception); assertEquals(500, response.getStatus()); assertEquals(TEXT_PLAIN_TYPE, response.getMediaType()); assertEquals(exception.getMessage(), response.getEntity()); }
@Test public void createsResponseWithStatus500AndUsesFullClassNameOfExceptionAsEntity() { Exception exception = new Exception(); Response response = exceptionMapper.toResponse(exception); assertEquals(500, response.getStatus()); assertEquals(TEXT_PLAIN_TYPE, response.getMediaType()); assertEquals(exception.getClass().getName(), response.getEntity()); }