use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class BackendGlusterBrickResourceTest method testReplace.
@Test
public void testReplace() throws Exception {
try {
resource.replace(new Action());
fail("Expected excpetion");
} catch (WebApplicationException wae) {
assertTrue(wae.getResponse().getEntity() instanceof Fault);
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class UsageFinderTest method testAdd.
@Test
public void testAdd() {
try {
UriInfo uriInfo = mockUri("hosts", "00000001-0001-0001-0001-000000000011", "nics");
Request request = mockRequest("POST");
Fault fault = usageFinder.getUsageMessage(uriInfo, request);
assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/host_nics/methods/add", fault.getDetail());
} catch (ClassNotFoundException | IOException | URISyntaxException e) {
fail();
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class UsageFinderTest method testUpdateWithNonGuidId.
@Test
public void testUpdateWithNonGuidId() {
try {
// LUN id.
UriInfo uriInfo = mockUri("hosts", "00000001-0001-0001-0001-000000000011", "nics", "116");
Request request = mockRequest("PUT");
Fault fault = usageFinder.getUsageMessage(uriInfo, request);
assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/host_nic/methods/update", fault.getDetail());
} catch (URISyntaxException | ClassNotFoundException | IOException e) {
fail();
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class IOExceptionMapper method toResponse.
@Override
public Response toResponse(IOException exception) {
// Check if the cause of the exception is an invalid value, and generate a specific error message:
Throwable cause = exception.getCause();
if (cause instanceof InvalidValueException) {
Fault fault = new Fault();
fault.setReason("Invalid value");
fault.setDetail(cause.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(fault).build();
}
// the request:
try {
log.error("IO exception while processing \"{}\" request for path \"{}\"", request.getMethod(), uriInfo.getPath());
log.error("Exception", exception);
UsageFinder finder = new UsageFinder();
return Response.status(Status.BAD_REQUEST).entity(finder.getUsageMessage(uriInfo, request)).build();
} catch (Exception error) {
throw new WebApplicationException(error, Response.status(Status.INTERNAL_SERVER_ERROR).build());
}
}
use of org.ovirt.engine.api.model.Fault in project ovirt-engine by oVirt.
the class MalformedIdExceptionMapper method toResponse.
@Override
public Response toResponse(MalformedIdException exception) {
log.error("Malformed id detected while processing \"{}\" request for path \"{}\"", request.getMethod(), uriInfo.getPath());
log.error("Exception", exception);
final Fault fault = new Fault();
fault.setReason("Operation failed");
fault.setDetail(exception.getCause().getMessage());
return Response.status(Status.BAD_REQUEST).entity(fault).build();
}
Aggregations