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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations