use of com.poc.restfulpoc.config.ApiError in project POC by rajadilipkolli.
the class RestExceptionHandler method handleHttpMessageNotReadable.
/**
* {@inheritDoc}
*
* Handle HttpMessageNotReadableException. Happens when request JSON is malformed.
*/
@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
final ServletWebRequest servletWebRequest = (ServletWebRequest) request;
log.info("{} to {}", servletWebRequest.getHttpMethod(), servletWebRequest.getRequest().getServletPath());
final String error = "Malformed JSON request";
return buildResponseEntity(new ApiError(BAD_REQUEST, error, ex));
}
use of com.poc.restfulpoc.config.ApiError in project POC by rajadilipkolli.
the class RestExceptionHandler method handleMethodArgumentTypeMismatch.
/**
* Handle Exception, handle generic Exception.class
*
* @param ex the Exception
* @return the ApiError object
* @param request a {@link org.springframework.web.context.request.WebRequest} object.
*/
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
protected ResponseEntity<Object> handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException ex, WebRequest request) {
final ApiError apiError = new ApiError(BAD_REQUEST);
apiError.setMessage(String.format("The parameter '%s' of value '%s' could not be converted to type '%s'", ex.getName(), ex.getValue(), ex.getRequiredType().getSimpleName()));
apiError.setDebugMessage(ex.getMessage());
return buildResponseEntity(apiError);
}
Aggregations