@Override public String toString() { StringBuilder sb = new StringBuilder("com.haulmont.cuba.core.global.RemoteException:"); for (Cause cause : causes) { sb.append("\n---\n").append(cause.getClassName()).append(": ").append(cause.getMessage()); } return sb.toString(); } }
/** * Search for {@link Cause} by its exception class name. Subclasses are not taken into account. * * @param throwableClassName exception class name * @return Cause instance or null if it is not found */ @Nullable public Cause getCause(String throwableClassName) { for (Cause cause : causes) { if (cause.getClassName().equals(throwableClassName)) { return cause; } } return null; }
} else { String className = cause.getClassName(); if (className != null && className.indexOf('.') > 0) { className = className.substring(className.lastIndexOf('.') + 1);
List<RemoteException.Cause> causes = ((RemoteException) rootCause).getCauses(); RemoteException.Cause cause = causes.get(causes.size() - 1); msg = cause.getThrowable() != null ? cause.getThrowable().toString() : cause.getClassName() + ": " + cause.getMessage(); } else { msg = rootCause.toString();
@Override public boolean handle(ErrorEvent event, App app) { Throwable exception = event.getThrowable(); List<Throwable> list = ExceptionUtils.getThrowableList(exception); for (Throwable throwable : list) { if (classNames.contains(throwable.getClass().getName()) && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) { doHandle(app, throwable.getClass().getName(), throwable.getMessage(), throwable); return true; } if (throwable instanceof RemoteException) { RemoteException remoteException = (RemoteException) throwable; for (RemoteException.Cause cause : remoteException.getCauses()) { if (classNames.contains(cause.getClassName()) && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) { doHandle(app, cause.getClassName(), cause.getMessage(), cause.getThrowable()); return true; } } } } return false; }
@Override public boolean handle(Throwable exception, UiContext context) { List<Throwable> list = ExceptionUtils.getThrowableList(exception); for (Throwable throwable : list) { if (classNames.contains(throwable.getClass().getName()) && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) { doHandle(throwable.getClass().getName(), throwable.getMessage(), throwable, context); return true; } if (throwable instanceof RemoteException) { RemoteException remoteException = (RemoteException) throwable; for (RemoteException.Cause cause : remoteException.getCauses()) { if (classNames.contains(cause.getClassName()) && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) { doHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable(), context); return true; } } } } return false; }
@Override public boolean handle(Throwable exception, WindowManager windowManager) { List<Throwable> list = ExceptionUtils.getThrowableList(exception); for (Throwable throwable : list) { if (classNames.contains(throwable.getClass().getName()) && canHandle(throwable.getClass().getName(), throwable.getMessage(), throwable)) { doHandle(throwable.getClass().getName(), throwable.getMessage(), throwable, windowManager); return true; } if (throwable instanceof RemoteException) { RemoteException remoteException = (RemoteException) throwable; for (RemoteException.Cause cause : remoteException.getCauses()) { if (classNames.contains(cause.getClassName()) && canHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable())) { doHandle(cause.getClassName(), cause.getMessage(), cause.getThrowable(), windowManager); return true; } } } } return false; }
@ExceptionHandler(Exception.class) @ResponseBody public ResponseEntity<ErrorInfo> handleException(Exception e) { log.error("Exception in REST controller", e); @SuppressWarnings("unchecked") List<Throwable> list = ExceptionUtils.getThrowableList(e); for (Throwable throwable : list) { if (throwable instanceof RemoteException) { RemoteException remoteException = (RemoteException) throwable; for (RemoteException.Cause cause : remoteException.getCauses()) { if (Objects.equals("javax.persistence.OptimisticLockException", cause.getClassName())) { ErrorInfo errorInfo = new ErrorInfo("Optimistic lock", cause.getMessage()); return new ResponseEntity<>(errorInfo, HttpStatus.BAD_REQUEST); } } } } ErrorInfo errorInfo = new ErrorInfo("Server error", ""); return new ResponseEntity<>(errorInfo, HttpStatus.INTERNAL_SERVER_ERROR); }
@Override public boolean handle(Throwable exception, WindowManager windowManager) { List<Throwable> list = ExceptionUtils.getThrowableList(exception); for (Throwable throwable : list) { if (className.contains(throwable.getClass().getName()) && isDateOutOfRangeMessage(throwable.getMessage())) { doHandle(windowManager); return true; } if (throwable instanceof RemoteException) { RemoteException remoteException = (RemoteException) throwable; for (RemoteException.Cause cause : remoteException.getCauses()) { if (className.contains(cause.getClassName()) && isDateOutOfRangeMessage(throwable.getMessage())) { doHandle(windowManager); return true; } } } } return false; }