Skip to content

Commit

Permalink
fix: Improve exception notification looks
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuJLund committed Nov 21, 2024
1 parent e102d56 commit b3e2041
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Despites being somewhat artificial this demo app covers various use cases you ma
- Implement beforeLeave to confirm unsaved changes
- Highlight changed fields
- Bean level validation example
- Display no matches label on Grid when search did not find matches
- Bookmarkable editor
- Description generator showing details in compact mode
- Pessimistic locking preventing concurrent edits
Expand Down
2 changes: 1 addition & 1 deletion vaadincreate-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-charts</artifactId>
<version>4.3.4</version>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
Expand Down Expand Up @@ -43,10 +44,10 @@
import com.vaadin.server.VaadinSession;
import com.vaadin.server.WrappedSession;
import com.vaadin.shared.ui.ui.Transport;
import com.vaadin.ui.JavaScript;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.UI;
import com.vaadin.ui.themes.ValoTheme;

@Theme("vaadincreate")
@StyleSheet("vaadin://styles/additional-styles.css")
Expand Down Expand Up @@ -92,9 +93,10 @@ private void onLogin() {
showAppLayout();
}

public void showInternalError(String message) {
Notification.show(getTranslation(I18n.EXCEPTION, message),
Type.ERROR_MESSAGE);
public void showInternalError(String message, String id) {
var failure = Notification.show(getTranslation(I18n.EXCEPTION, id),
message, Type.ERROR_MESSAGE);
failure.setStyleName(ValoTheme.NOTIFICATION_FAILURE);
}

private String getInitialTarget() {
Expand Down Expand Up @@ -278,6 +280,8 @@ public ExecutorService getExecutor() {
@VaadinServletConfiguration(productionMode = false, ui = VaadinCreateUI.class, heartbeatInterval = 60, closeIdleSessions = true)
public static class Servlet extends VaadinServlet {

final AtomicInteger exceptionCount = new AtomicInteger(1);

@Override
protected void servletInitialized() {
// Disable session expired notification and redirect to login view
Expand All @@ -304,11 +308,12 @@ protected void servletInitialized() {
// https://github.com/jetty/jetty.project/issues/9763
if (!(throwable.toString()
.contains("org.eclipse.jetty.io.EofException"))) {
var message = throwable.getLocalizedMessage();
String id = formatId();
var message = throwable.getMessage();
session.getUIs().forEach(
ui -> ui.access(() -> ((VaadinCreateUI) ui)
.showInternalError(message)));
logger.error("Exception happened",
.showInternalError(message, id)));
logger.error("Exception happened {}", id,
errorHandler.getThrowable());
}
});
Expand All @@ -327,6 +332,13 @@ protected void servletInitialized() {
});
}

private String formatId() {
return String
.format("#%10s",
String.valueOf(exceptionCount.getAndAdd(1)))
.replace(' ', '0');
}

// Use request handler to persist the selected language to Cookie
private boolean handleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) {
Expand Down

0 comments on commit b3e2041

Please sign in to comment.