Search in sources :

Example 1 with ApplicationException

use of org.jboss.resteasy.spi.ApplicationException in project stdlib by petergeneric.

the class RestFailureMarshaller method renderFailure.

/**
 * Render a Throwable as a RestFailure
 *
 * @param e
 *
 * @return
 */
public RestFailure renderFailure(Throwable e) {
    // Strip away ApplicationException wrappers
    if (e.getCause() != null && (e instanceof ApplicationException)) {
        return renderFailure(e.getCause());
    }
    RestFailure failure = new RestFailure();
    failure.id = getOrGenerateFailureId();
    failure.date = new Date();
    if (e instanceof RestException) {
        RestException re = (RestException) e;
        failure.httpCode = re.getHttpCode();
        failure.exception = renderThrowable(e);
    } else {
        // by default
        failure.httpCode = 500;
        failure.exception = renderThrowable(e);
    }
    return failure;
}
Also used : ApplicationException(org.jboss.resteasy.spi.ApplicationException) RestFailure(com.peterphi.std.guice.restclient.jaxb.RestFailure) RestException(com.peterphi.std.guice.restclient.exception.RestException) Date(java.util.Date)

Example 2 with ApplicationException

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

the class ApplicationExceptionMapperTest method noCause.

@Test
public void noCause() {
    ApplicationException ae = new ApplicationException("oops", null);
    ApplicationExceptionMapper aem = injector.getInstance(ApplicationExceptionMapper.class);
    Response r = aem.toResponse(ae);
    assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
    verifyMessage(r, rtmsg("oops"));
}
Also used : Response(javax.ws.rs.core.Response) ApplicationException(org.jboss.resteasy.spi.ApplicationException) Test(org.junit.Test)

Example 3 with ApplicationException

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

the class ApplicationExceptionMapperTest method withCause.

@Test
public void withCause() {
    EOFException eofe = new EOFException("screwed");
    ApplicationException ae = new ApplicationException("oops", eofe);
    ApplicationExceptionMapper aem = injector.getInstance(ApplicationExceptionMapper.class);
    Response r = aem.toResponse(ae);
    assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus());
    verifyMessage(r, rtmsg("oops"));
}
Also used : Response(javax.ws.rs.core.Response) ApplicationException(org.jboss.resteasy.spi.ApplicationException) EOFException(java.io.EOFException) Test(org.junit.Test)

Aggregations

ApplicationException (org.jboss.resteasy.spi.ApplicationException)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 RestException (com.peterphi.std.guice.restclient.exception.RestException)1 RestFailure (com.peterphi.std.guice.restclient.jaxb.RestFailure)1 EOFException (java.io.EOFException)1 Date (java.util.Date)1