use of org.springframework.web.bind.annotation.ExceptionHandler in project free-framework by a601942905git.
the class GlobalExceptionHandler method defaultErrorHandler.
/**
* 当控制器方法抛出exception异常,执行该方法
* 根据异常类型执行对应的方法
* @param request
* @param e
* @return
*/
@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) {
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", request.getRequestURL());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project data-prep by Talend.
the class TDPExceptionController method handleInvalidArguments.
/**
* This method is invoked when Spring throw an MethodArgumentNotValidException. This happen because @RequestMapping annotated
* methods may have @Valid annotated arguments and validation may fail.
*/
@ExceptionHandler({ MethodArgumentNotValidException.class })
public ResponseEntity<String> handleInvalidArguments(MethodArgumentNotValidException e) throws JsonProcessingException {
final HttpHeaders httpHeaders = new HttpHeaders();
final Map<String, Object> context = new HashMap<>();
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
context.put("binding_results", e.getBindingResult().getAllErrors());
TdpExceptionDto exceptionDto = new TdpExceptionDto(CommonErrorCodes.UNEXPECTED_CONTENT.getCode(), null, e.getMessage(), e.getLocalizedMessage(), "Invalid argument", context);
return new ResponseEntity<>(objectMapper.writeValueAsString(exceptionDto), httpHeaders, NOT_ACCEPTABLE);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project POC by rajadilipkolli.
the class RestExceptionHandler method handleEntityNotFound.
/**
* Handles EntityNotFoundException. Created to encapsulate errors with more detail
* than javax.persistence.EntityNotFoundException.
*
* @param ex the EntityNotFoundException
* @return the ApiError object
*/
@ExceptionHandler(EntityNotFoundException.class)
protected ResponseEntity<Object> handleEntityNotFound(EntityNotFoundException ex) {
final ApiError apiError = new ApiError(NOT_FOUND);
apiError.setMessage(ex.getMessage());
return buildResponseEntity(apiError);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project metalnx-web by irods-contrib.
the class TicketClientExceptionController method handleTicketFileNotFound.
@ExceptionHandler({ DataGridTicketDownloadException.class })
public ModelAndView handleTicketFileNotFound(DataGridTicketDownloadException e) {
ticketClientService.deleteTempTicketDir();
String path = e.getPath();
String objName = path.substring(path.lastIndexOf(IRODS_PATH_SEPARATOR) + 1, path.length());
ModelAndView mav = new ModelAndView();
mav.addObject("error", e.getMessage());
mav.addObject("objName", objName);
mav.addObject("path", path);
mav.addObject("ticketString", e.getTicketString());
String viewName = "tickets/ticketclient";
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
if (loggedUser != null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
UserTokenDetails userTokenDetails = (UserTokenDetails) auth.getDetails();
mav.addObject("userDetails", userTokenDetails.getUser());
viewName = "tickets/ticketAuthAccess";
}
mav.setViewName(viewName);
return mav;
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project FP-PSP-SERVER by FundacionParaguaya.
the class ExceptionTranslatorAdvice method handleGeneralUncaughtExcption.
/**
* <p>
* Any other unhandled exceptions are processed here.
* </p>
* <p>
* We also process user defined (non standard) exceptions annotated with @ResponseStatus.
* See {@link py.org.fundacionparaguaya.pspserver.common.exceptions.UnknownResourceException}
* </p>
* @param ex
* @return
*/
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleGeneralUncaughtExcption(Exception ex) {
HttpStatus status;
ErrorDTO errorDto;
ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class);
if (responseStatus != null) {
status = responseStatus.value();
errorDto = ErrorDTO.of(responseStatus.reason(), ex.getLocalizedMessage()).formatWithCode();
} else {
status = HttpStatus.INTERNAL_SERVER_ERROR;
errorDto = ErrorDTO.of(ErrorCodes.INTERNAL_SERVER_ERROR.getMessage(), ex.getLocalizedMessage()).formatWithCode();
}
LOG.error("Error id: {}", errorDto.getErrorId());
LOG.error(ex.getMessage(), ex);
return generateResponseEntity(errorDto, status);
}
Aggregations