Search in sources :

Example 1 with InternalServerErrorException

use of org.jboss.resteasy.spi.InternalServerErrorException in project candlepin by candlepin.

the class InternalServerErrorExceptionMapperTest method handleISE.

@Test
public void handleISE() {
    InternalServerErrorException isee = new InternalServerErrorException("fubarred");
    InternalServerErrorExceptionMapper iseem = injector.getInstance(InternalServerErrorExceptionMapper.class);
    Response r = iseem.toResponse(isee);
    assertEquals(500, r.getStatus());
    verifyMessage(r, rtmsg("fubarred"));
}
Also used : Response(javax.ws.rs.core.Response) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) Test(org.junit.Test)

Example 2 with InternalServerErrorException

use of org.jboss.resteasy.spi.InternalServerErrorException in project teiid by teiid.

the class TeiidRSExceptionHandler method toResponse.

@Override
public Response toResponse(Exception e) {
    ResponseError error = new ResponseError();
    // $NON-NLS-1$
    String code = "ERROR";
    if (e instanceof NotAuthorizedException) {
        // $NON-NLS-1$
        code = "401";
    } else if (e instanceof NotFoundException) {
        // $NON-NLS-1$
        code = "404";
    } else if (e instanceof InternalServerErrorException) {
        // $NON-NLS-1$
        code = "500";
    } else if (e instanceof WebApplicationException) {
        // $NON-NLS-1$
        code = "500";
    }
    error.setCode(code);
    error.setMessage(e.getMessage());
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    error.setDetails(sw.toString());
    String type = MediaType.APPLICATION_XML;
    List<MediaType> acceptTypes = httpHeaders.getAcceptableMediaTypes();
    if (acceptTypes != null) {
        for (MediaType acceptType : acceptTypes) {
            if (isApplicationJsonWithParametersIgnored(acceptType)) {
                type = MediaType.APPLICATION_JSON;
                break;
            }
        }
    }
    return Response.serverError().entity(error).type(type).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) StringWriter(java.io.StringWriter) NotFoundException(javax.ws.rs.NotFoundException) InternalServerErrorException(org.jboss.resteasy.spi.InternalServerErrorException) MediaType(javax.ws.rs.core.MediaType) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) PrintWriter(java.io.PrintWriter)

Aggregations

InternalServerErrorException (org.jboss.resteasy.spi.InternalServerErrorException)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 NotFoundException (javax.ws.rs.NotFoundException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1