use of org.springframework.web.bind.annotation.ExceptionHandler in project spring-boot-starter-kit by tripsta.
the class ExceptionHandlingAdvisor method handleMethodArgumentNotValidException.
@ExceptionHandler(MethodArgumentNotValidException.class)
public HttpEntity<ApiErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
logger.warn("Invalid request " + e.getMessage(), e);
List<ApiError> errorsList = new ArrayList<ApiError>();
ApiErrorResponse errorResponse = new ApiErrorResponse();
for (ObjectError error : e.getBindingResult().getAllErrors()) {
String errorMsg = createErrorMessage(error);
errorsList.add(new ApiError(errorMsg, ExceptionType.FIELD_VALIDATION));
}
errorResponse.addErrors(errorsList);
return new ResponseEntity<ApiErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project uhgroupings by uhawaii-system-its-ti-iam.
the class ErrorControllerAdvice method handleTypeMismatchException.
// todo this is for the HolidayRestControllerTest test (should we really have this behavior?)
@ExceptionHandler(TypeMismatchException.class)
public String handleTypeMismatchException(Exception ex) {
String username = null;
User user = userContextService.getCurrentUser();
if (user != null) {
username = user.getUsername();
}
logger.error("username: " + username + "; Exception: ", ex);
return "redirect:/error";
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project open-kilda by telstra.
the class NorthboundExceptionHandler method handleMessageException.
/**
* Handles NorthboundException exception.
*
* @param exception the NorthboundException instance
* @param request the WebRequest caused exception
* @return the ResponseEntity object instance
*/
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
HttpStatus status;
switch(exception.getErrorType()) {
case NOT_FOUND:
status = HttpStatus.NOT_FOUND;
break;
case DATA_INVALID:
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case OPERATION_TIMED_OUT:
case INTERNAL_ERROR:
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(), exception.getErrorType().toString(), exception.getMessage(), exception.getErrorDescription());
logger.warn(format("Error %s caught.", error), exception);
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project perry by ca-cwds.
the class LoginResourceExceptionHandler method handleException.
@ExceptionHandler(value = { Exception.class })
protected ModelAndView handleException(Exception ex, WebRequest request) {
logger.error(ex.getMessage(), ex);
ModelAndView modelAndView = new ModelAndView(ERROR_CONTROLLER);
request.setAttribute(ERROR_MESSAGE, ex, SCOPE_REQUEST);
return modelAndView;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project entando-core by entando.
the class RestExceptionHandler method processValidationError.
@ExceptionHandler(value = ValidationUpdateSelfException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)
@ResponseBody
public RestResponse processValidationError(ValidationUpdateSelfException ex) {
logger.debug("Handling {} error", ex.getClass().getSimpleName());
BindingResult result = ex.getBindingResult();
RestResponse response = processAllErrors(result);
return response;
}
Aggregations