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"));
}
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"));
}
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;
}
Aggregations