use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.
the class ExceptionHandlingController method handleNotFoundError.
@ExceptionHandler({ NoHandlerFoundException.class })
public void handleNotFoundError(HttpServletRequest request, HttpServletResponse response) throws Exception {
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler() {
@Override
protected Resource getResource(HttpServletRequest request) throws IOException {
String requestPath = request.getRequestURI().substring(request.getContextPath().length());
ClassPathResource resource = new ClassPathResource(STATIC_CONTENT_FOLDER + requestPath);
if (!resource.exists()) {
resource = new ClassPathResource(INDEX_FILE);
}
return resource;
}
};
handler.setServletContext(webApplicationContext.getServletContext());
handler.setLocations(Collections.singletonList(new ClassPathResource("classpath:/" + STATIC_CONTENT_FOLDER + "/")));
handler.afterPropertiesSet();
handler.handleRequest(request, response);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.
the class ExceptionHandlingController method exceptionHandler.
@ExceptionHandler(AlreadyExistException.class)
public ResponseEntity<JsonResult> exceptionHandler(AlreadyExistException ex) {
LOGGER.error(ex.getMessage(), ex);
JsonResult result = new JsonResult<>(ALREADY_EXIST);
result.setErrorMessage(ex.getMessage());
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.
the class ExceptionHandlingController method exceptionHandler.
@ExceptionHandler(NoExecutableFileException.class)
public ResponseEntity<JsonResult> exceptionHandler(NoExecutableFileException ex) {
LOGGER.error(ex.getMessage(), ex);
JsonResult result = new JsonResult(VALIDATION_ERROR);
result.setErrorMessage(ex.getMessage());
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project ArachneCentralAPI by OHDSI.
the class ExceptionHandlingController method exceptionHandler.
@ExceptionHandler(PasswordValidationException.class)
public ResponseEntity<JsonResult> exceptionHandler(PasswordValidationException ex) {
LOGGER.error("User tried to register with weak password");
JsonResult result = new JsonResult<>(VALIDATION_ERROR);
result.setErrorMessage("You have provided a weak password");
final ArachnePasswordInfoDTO passwordInfoDTO = conversionService.convert(ex.getPasswordInfo(), ArachnePasswordInfoDTO.class);
result.getValidatorErrors().put("password", passwordInfoDTO);
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project nixmash-blog by mintster.
the class GlobalController method handleContactNotFoundException.
@ExceptionHandler(ContactNotFoundException.class)
public ModelAndView handleContactNotFoundException() {
logger.debug("In ContactNotFound Exception Handler");
ModelAndView mav = new ModelAndView();
mav.addObject(ERROR_PAGE_TITLE_ATTRIBUTE, "Contact Missing in Action!");
mav.addObject(ERROR_PAGE_MESSAGE_ATTRIBUTE, "We'll find the rascal, don't you worry");
mav.setViewName(ERROR_CUSTOM_VIEW);
return mav;
}
Aggregations