Search in sources :

Example 1 with Failure

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

the class FailureExceptionMapperTest method handleExceptionWithResponse.

@Test
public void handleExceptionWithResponse() {
    Response mockr = mock(Response.class);
    when(mockr.getStatus()).thenReturn(500);
    Failure nfe = new Failure("unacceptable", mockr);
    FailureExceptionMapper nfem = injector.getInstance(FailureExceptionMapper.class);
    Response r = nfem.toResponse(nfe);
    assertEquals(500, r.getStatus());
    verifyMessage(r, rtmsg("unacceptable"));
}
Also used : Response(javax.ws.rs.core.Response) Failure(org.jboss.resteasy.spi.Failure) Test(org.junit.Test)

Example 2 with Failure

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

the class FailureExceptionMapperTest method handleExceptionWithoutResponse.

@Test
public void handleExceptionWithoutResponse() {
    Failure nfe = new Failure("unacceptable");
    FailureExceptionMapper nfem = injector.getInstance(FailureExceptionMapper.class);
    Response r = nfem.toResponse(nfe);
    assertEquals(400, r.getStatus());
    verifyMessage(r, rtmsg("unacceptable"));
}
Also used : Response(javax.ws.rs.core.Response) Failure(org.jboss.resteasy.spi.Failure) Test(org.junit.Test)

Example 3 with Failure

use of org.jboss.resteasy.spi.Failure in project keycloak by keycloak.

the class KeycloakErrorHandler method getStatusCode.

private int getStatusCode(Throwable throwable) {
    int status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
    if (throwable instanceof WebApplicationException) {
        WebApplicationException ex = (WebApplicationException) throwable;
        status = ex.getResponse().getStatus();
    }
    if (throwable instanceof Failure) {
        Failure f = (Failure) throwable;
        status = f.getErrorCode();
    }
    if (throwable instanceof JsonParseException) {
        status = Response.Status.BAD_REQUEST.getStatusCode();
    }
    if (throwable instanceof ModelDuplicateException) {
        status = Response.Status.CONFLICT.getStatusCode();
    }
    return status;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ModelDuplicateException(org.keycloak.models.ModelDuplicateException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Failure(org.jboss.resteasy.spi.Failure)

Aggregations

Failure (org.jboss.resteasy.spi.Failure)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ModelDuplicateException (org.keycloak.models.ModelDuplicateException)1