Search in sources :

Example 1 with InvalidFieldException

use of org.onosproject.net.config.InvalidFieldException in project onos by opennetworkinglab.

the class InvalidConfigExceptionMapper method response.

@Override
protected Response.ResponseBuilder response(Response.Status status, Throwable exception) {
    error = exception;
    InvalidConfigException ex = (InvalidConfigException) exception;
    ObjectMapper mapper = new ObjectMapper();
    String message = messageFrom(exception);
    ObjectNode result = mapper.createObjectNode().put("code", status.getStatusCode()).put("message", message).put("subjectKey", ex.subjectKey()).put("subject", ex.subject()).put("configKey", ex.configKey());
    if (ex.getCause() instanceof InvalidFieldException) {
        InvalidFieldException fieldException = (InvalidFieldException) ex.getCause();
        result.put("field", fieldException.field()).put("reason", fieldException.reason());
    }
    return Response.status(status).entity(result.toString());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InvalidConfigException(org.onosproject.net.config.InvalidConfigException) InvalidFieldException(org.onosproject.net.config.InvalidFieldException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InvalidConfigException (org.onosproject.net.config.InvalidConfigException)1 InvalidFieldException (org.onosproject.net.config.InvalidFieldException)1