Search in sources :

Example 51 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project tutorials by eugenp.

the class RestResponseEntityExceptionHandler method handleInternal.

// 412
// 500
@ExceptionHandler({ NullPointerException.class, IllegalArgumentException.class, IllegalStateException.class })
public /*500*/
ResponseEntity<Object> handleInternal(final RuntimeException ex, final WebRequest request) {
    logger.error("500 Status Code", ex);
    final String bodyOfResponse = "This should be application specific";
    return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 52 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project dubidubi by lzzzz4.

the class BaseExceptionController method ajaxUnAuthorHandle.

@ExceptionHandler(UnauthorizedException.class)
@ResponseBody
public /**
 * @Description:当ajax请求页面时,未授权用户抛出的异常处理
 * @param response
 * @return
 */
AjaxResultDTO ajaxUnAuthorHandle(HttpServletResponse response) {
    AjaxResultDTO ajaxResultDTO = new AjaxResultDTO();
    // 设置错误码为1000,授权失败
    ajaxResultDTO.setCode(1000);
    return ajaxResultDTO;
}
Also used : AjaxResultDTO(cn.dubidubi.model.base.dto.AjaxResultDTO) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 53 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project motech by motech.

the class UserController method handlePasswordValidatorException.

@ExceptionHandler(PasswordValidatorException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public String handlePasswordValidatorException(HttpServletRequest request, PasswordValidatorException ex) {
    LOGGER.debug("Password did not pass validation: {}", ex.getMessage());
    Locale locale = localeService.getUserLocale(request);
    String errorMsg = settingService.getPasswordValidator().getValidationError(locale);
    return "literal:" + errorMsg;
}
Also used : Locale(java.util.Locale) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 54 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project irida by phac-nml.

the class ExceptionHandlerController method handleResourceNotFoundException.

/**
 * Handle an {@link EntityNotFoundException} and return an http 404
 *
 * @param ex
 *            The EntityNotFoundException caught
 * @return the name of the not_found view
 */
@ExceptionHandler(EntityNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView handleResourceNotFoundException(EntityNotFoundException ex) {
    logger.error(ex.getMessage(), ex);
    ModelAndView modelAndView = new ModelAndView(NOT_FOUND_PAGE);
    modelAndView.addObject("adminEmail", adminEmail);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 55 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project irida by phac-nml.

the class ExceptionHandlerController method handleOtherExceptions.

/**
 * Catch all other exception types and display a generic error page and 500
 * error
 *
 * @param ex
 *            The caught exception
 * @return Name of the generic error page
 */
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleOtherExceptions(Exception ex) {
    logger.error(ex.getMessage(), ex);
    ModelAndView modelAndView = new ModelAndView(OTHER_ERROR_PAGE);
    modelAndView.addObject("adminEmail", adminEmail);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

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