use of org.springframework.web.bind.annotation.ExceptionHandler in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(AccessDeniedException.class)
ResponseEntity<ResultModels> handle(AccessDeniedException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.FORBIDDEN, ex.getMessage());
log.warn("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
ResponseEntity<ResultModels> handle(HttpRequestMethodNotSupportedException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.METHOD_NOT_ALLOWED, ex.getMessage(), //
ImmutableMap.of(//
"errorMethod", //
ex.getMethod(), "supportedMethods", StringUtils.join(ex.getSupportedMethods(), ", ")));
log.warn("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(CoreException.class)
ResponseEntity<ResultModels> handle(CoreException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR, ex.getMessage(), ex.getDetails());
log.error("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(HttpMessageNotReadableException.class)
ResponseEntity<ResultModels> handle(HttpMessageNotReadableException ex) {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.METHOD_NOT_ALLOWED, ex.getMessage());
log.warn("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
use of org.springframework.web.bind.annotation.ExceptionHandler in project CzechIdMng by bcvsolutions.
the class ExceptionControllerAdvice method handle.
@ExceptionHandler(Exception.class)
ResponseEntity<ResultModels> handle(Exception ex) {
Throwable cause = Throwables.getRootCause(ex);
// If is cause instance of ResultCodeException, then we will log catched exception and throw only ResultCodeException (for better show on frontend)
if (cause instanceof ResultCodeException) {
log.error(ex.getLocalizedMessage(), ex);
return handle((ResultCodeException) cause);
} else {
ErrorModel errorModel = new DefaultErrorModel(CoreResultCode.INTERNAL_SERVER_ERROR, ex.getMessage());
log.error("[" + errorModel.getId() + "] ", ex);
return new ResponseEntity<>(new ResultModels(errorModel), new HttpHeaders(), errorModel.getStatus());
}
}
Aggregations