Search in sources :

Example 6 with ExceptionHandler

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

the class AbstractManagementController method resolveException.

/**
     * Resolve exception.
     *
     * @param request the request
     * @param response the response
     * @param ex the exception
     * @return the model and view
     * @throws IOException the iO exception
     */
@ExceptionHandler
public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response, final Exception ex) throws IOException {
    LOGGER.error(ex.getMessage(), ex);
    final String contentType = request.getHeader(AJAX_REQUEST_HEADER_NAME);
    if (contentType != null && contentType.equals(AJAX_REQUEST_HEADER_VALUE)) {
        LOGGER.debug("Handling exception [{}] for ajax request indicated by header [{}]", ex.getClass().getName(), AJAX_REQUEST_HEADER_NAME);
        JsonUtils.renderException(ex, response);
        return null;
    }
    LOGGER.trace("Unable to resolve exception [{}] for request. AJAX request header [{}] not found.", ex.getClass().getName(), AJAX_REQUEST_HEADER_NAME);
    final ModelAndView mv = new ModelAndView("error");
    mv.addObject(ex);
    return mv;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 7 with ExceptionHandler

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

the class CustomExceptionHandler method handleGeneralException.

@ExceptionHandler(value = { Exception.class })
public final ResponseEntity<ErrorResult> handleGeneralException(Exception ex, HttpServletRequest request) {
    logError(ex, request);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(MediaTypes.JSON_UTF_8));
    ErrorResult result = new ErrorResult(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
    return new ResponseEntity<ErrorResult>(result, headers, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ResponseEntityExceptionHandler(org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 8 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleMethodResultValidationException.

@ExceptionHandler(MethodResultValidationException.class)
@ResponseBody
public ResponseEntity<ErrorInfo> handleMethodResultValidationException(MethodResultValidationException e) {
    log.error("MethodResultValidationException in service", e);
    ErrorInfo errorInfo = new ErrorInfo("Server error", "");
    return new ResponseEntity<>(errorInfo, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorInfo(com.haulmont.restapi.exception.ErrorInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project cuba by cuba-platform.

the class RestControllerExceptionHandler method handleValidationException.

@ExceptionHandler(ValidationException.class)
@ResponseBody
public ResponseEntity<ErrorInfo> handleValidationException(ValidationException e) {
    log.error("ValidationException in service", e);
    ErrorInfo errorInfo = new ErrorInfo("Server error", "");
    return new ResponseEntity<>(errorInfo, HttpStatus.INTERNAL_SERVER_ERROR);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ErrorInfo(com.haulmont.restapi.exception.ErrorInfo) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with ExceptionHandler

use of org.springframework.web.bind.annotation.ExceptionHandler in project spring-boot-starter-kit by tripsta.

the class ExceptionHandlingAdvisor method handleNoSessionIdException.

/**
 * NoSessionIdException,
 * Session Id is required
 *
 * @param e
 * @return
 */
@ExceptionHandler(NoSessionIdException.class)
public HttpEntity<ApiErrorResponse> handleNoSessionIdException(NoSessionIdException e) {
    logger.warn("Session Id is required " + e.getMessage(), e);
    ApiErrorResponse errorResponse = new ApiErrorResponse();
    errorResponse.addError(new ApiError("session id is required", ExceptionType.ADVISORY));
    return new ResponseEntity<ApiErrorResponse>(errorResponse, HttpStatus.BAD_REQUEST);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiErrorResponse(com.sbsk.model.ApiErrorResponse) ApiError(com.sbsk.model.ApiError) 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