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);
}
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);
}
Aggregations