Search in sources :

Example 31 with ExceptionHandler

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceHttpRequestHandler(org.springframework.web.servlet.resource.ResourceHttpRequestHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 32 with ExceptionHandler

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 33 with ExceptionHandler

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 34 with ExceptionHandler

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArachnePasswordInfoDTO(com.odysseusinc.arachne.commons.api.v1.dto.ArachnePasswordInfoDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 35 with ExceptionHandler

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Aggregations

ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)178 ResponseEntity (org.springframework.http.ResponseEntity)58 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)48 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)41 HttpHeaders (org.springframework.http.HttpHeaders)39 ModelAndView (org.springframework.web.servlet.ModelAndView)33 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)31 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)17 HttpStatus (org.springframework.http.HttpStatus)13 AjaxJson (com.cdeledu.common.base.AjaxJson)12 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)8 DefaultErrorModel (eu.bcvsolutions.idm.core.api.exception.DefaultErrorModel)8 ErrorModel (eu.bcvsolutions.idm.core.api.exception.ErrorModel)8 RestResponse (org.entando.entando.web.common.model.RestResponse)8 ArrayList (java.util.ArrayList)7 BindingResult (org.springframework.validation.BindingResult)6 FieldError (org.springframework.validation.FieldError)5 ErrorInfo (com.haulmont.restapi.exception.ErrorInfo)4 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4