I’m implementing an exception handler using AbstractUiExceptionHandler, and I want to show the message of the exception, the problem with this is that the original exception is wrapped in vaadin exceptions. I attatch an example:
Default exception message:
New message using AbstractUiExceptionHandler:
This is my code:
@Override
protected void doHandle(String className, String message, @Nullable Throwable throwable, UiContext context) {
final User user = (User) currentAuthentication.getUser();
boolean isAdminUser = user.getAuthorities().stream()
.anyMatch(authority -> Objects.equals(authority.getAuthority(), FullAccessRole.CODE));
ExceptionScreen exceptionScreen = context.getScreens()
.create(ExceptionScreen.class, OpenMode.DIALOG);
exceptionScreen.setExceptionCaptionMessage(messageBundle.getMessage("unexpectedError"));
if (isAdminUser) {
exceptionScreen.setExceptionDescriptionMessage(message);
if (throwable != null) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
throwable.printStackTrace(printWriter);
exceptionScreen.setStackTraceMessage(stringWriter.toString());
}
} else {
exceptionScreen.setExceptionDescriptionMessage(messageBundle.getMessage("contactAdministrator"));
}
context.getScreens().show(exceptionScreen);
}