Search in sources :

Example 1 with InvalidValueException

use of org.ovirt.engine.api.utils.InvalidValueException 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());
    }
}
Also used : InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) WebApplicationException(javax.ws.rs.WebApplicationException) Fault(org.ovirt.engine.api.model.Fault) IOException(java.io.IOException) InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 2 with InvalidValueException

use of org.ovirt.engine.api.utils.InvalidValueException in project ovirt-engine by oVirt.

the class V3IOExceptionMapper 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) {
        V3Fault fault = new V3Fault();
        fault.setReason("Invalid value");
        fault.setDetail(cause.getMessage());
        return Response.status(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);
        V3UsageFinder finder = new V3UsageFinder();
        V3UsageMessage usage = finder.getUsageMessage(uriInfo, request);
        return Response.status(Status.BAD_REQUEST).entity(usage).build();
    } catch (Exception error) {
        throw new WebApplicationException(error, Response.status(Status.INTERNAL_SERVER_ERROR).build());
    }
}
Also used : InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) V3Fault(org.ovirt.engine.api.v3.types.V3Fault) WebApplicationException(javax.ws.rs.WebApplicationException) V3UsageMessage(org.ovirt.engine.api.v3.types.V3UsageMessage) IOException(java.io.IOException) InvalidValueException(org.ovirt.engine.api.utils.InvalidValueException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

IOException (java.io.IOException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 InvalidValueException (org.ovirt.engine.api.utils.InvalidValueException)2 Fault (org.ovirt.engine.api.model.Fault)1 V3Fault (org.ovirt.engine.api.v3.types.V3Fault)1 V3UsageMessage (org.ovirt.engine.api.v3.types.V3UsageMessage)1