Search in sources :

Example 1 with ErrorDetail

use of org.platformlayer.core.model.ErrorDetail in project platformlayer by platformlayer.

the class OpsExceptionMapper method toResponse.

@Override
public Response toResponse(OpsException e) {
    log.warn("Returning error to client", e);
    ErrorResponse error = new ErrorResponse();
    error.message = e.getMessage();
    if (e instanceof CustomerFacingException) {
        CustomerFacingException cfe = (CustomerFacingException) e;
        error.code = cfe.getCode();
        for (CustomerFacingException.Info info : cfe.getInfo()) {
            ErrorDetail errorInfo = new ErrorDetail();
            errorInfo.code = info.getCode();
            errorInfo.field = info.getField();
            errorInfo.message = info.getMessage();
            error.details.add(errorInfo);
        }
    }
    if (error.code == null) {
        error.code = e.getClass().getSimpleName();
    }
    ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
    response.entity(error);
    return response.build();
// VariantListBuilder variantListBuilder = VariantListBuilder.newInstance();
// variantListBuilder.mediaTypes(MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_XML_TYPE);
// List<Variant> variants = variantListBuilder.build();
// 
// Variant variant = httpContext.getRequest().selectVariant(variants);
// 
// ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
// 
// if (variant.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE)) {
// response.entity(error);
// 
// .entity(exception.getMessage()).type("text/plain").build();
// }
// else {
// .entity(exception.getMessage()).type("text/plain").build();
// }
// 
// return response.build();
}
Also used : ErrorDetail(org.platformlayer.core.model.ErrorDetail) CustomerFacingException(org.platformlayer.CustomerFacingException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ErrorResponse(org.platformlayer.core.model.ErrorResponse)

Aggregations

ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 CustomerFacingException (org.platformlayer.CustomerFacingException)1 ErrorDetail (org.platformlayer.core.model.ErrorDetail)1 ErrorResponse (org.platformlayer.core.model.ErrorResponse)1