Search in sources :

Example 1 with Reference

use of com.fasterxml.jackson.databind.JsonMappingException.Reference in project ezyhttp by youngmonkeys.

the class GlobalExceptionHandler method handleException.

@TryCatch(InvalidFormatException.class)
public void handleException(RequestArguments args, HttpServletRequest request, HttpServletResponse response, InvalidFormatException e) {
    e.printStackTrace();
    Map<String, String> data = new HashMap<>();
    for (Reference reference : e.getPath()) data.put(reference.getFieldName(), "invalid");
    throw new HttpBadRequestException(data);
}
Also used : HashMap(java.util.HashMap) Reference(com.fasterxml.jackson.databind.JsonMappingException.Reference) HttpBadRequestException(com.tvd12.ezyhttp.core.exception.HttpBadRequestException) TryCatch(com.tvd12.ezyhttp.server.core.annotation.TryCatch)

Example 2 with Reference

use of com.fasterxml.jackson.databind.JsonMappingException.Reference in project open-kilda by telstra.

the class GlobalExceptionMapper method handleHttpMessageNotReadable.

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(final HttpMessageNotReadableException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
    _log.error("Exception: " + ex.getMessage(), ex);
    String message = new String();
    if (ex.getCause() instanceof JsonMappingException) {
        StringBuilder msg = new StringBuilder();
        JsonMappingException jme = (JsonMappingException) ex.getCause();
        for (Reference reference : jme.getPath()) {
            msg.append(reference.getFieldName()).append(" -> ");
        }
        if (msg.length() > 0) {
            msg.setLength(msg.length() - 3);
            msg.append(": INVALID.");
        }
        message = msg.toString();
    } else {
        message = ex.getMessage();
    }
    return response(HttpError.UNPROCESSABLE_ENTITY.getHttpStatus(), HttpError.UNPROCESSABLE_ENTITY.getCode(), message, message);
}
Also used : Reference(com.fasterxml.jackson.databind.JsonMappingException.Reference) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

Reference (com.fasterxml.jackson.databind.JsonMappingException.Reference)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 HttpBadRequestException (com.tvd12.ezyhttp.core.exception.HttpBadRequestException)1 TryCatch (com.tvd12.ezyhttp.server.core.annotation.TryCatch)1 HashMap (java.util.HashMap)1