-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Error Handler not displaying Notification, make Views use ErrorHa…
…ndler Signed-off-by: Aleksandar Zivkovic <[email protected]>
- Loading branch information
1 parent
c25203c
commit e31a675
Showing
2 changed files
with
8 additions
and
34 deletions.
There are no files selected for viewing
25 changes: 6 additions & 19 deletions
25
src/main/java/com/samic/samic/views/SamicErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
package com.samic.samic.views; | ||
|
||
import com.samic.samic.components.UIFactory; | ||
import com.samic.samic.exceptions.SamicException; | ||
import com.vaadin.flow.component.UI; | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout; | ||
import com.vaadin.flow.router.BeforeEnterEvent; | ||
import com.vaadin.flow.router.ErrorParameter; | ||
import com.vaadin.flow.router.HasErrorParameter; | ||
import com.vaadin.flow.component.notification.Notification; | ||
import com.vaadin.flow.router.ParentLayout; | ||
import com.vaadin.flow.server.ErrorEvent; | ||
import com.vaadin.flow.server.ErrorHandler; | ||
import jakarta.annotation.security.PermitAll; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@PermitAll | ||
@ParentLayout(MainLayout.class) | ||
public class SamicErrorHandler extends VerticalLayout implements ErrorHandler, | ||
HasErrorParameter<SamicException> { | ||
public class SamicErrorHandler implements ErrorHandler { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(SamicErrorHandler.class); | ||
|
||
@Override | ||
public void error(ErrorEvent errorEvent) { | ||
logger.error("Something wrong happened", errorEvent.getThrowable()); | ||
if (UI.getCurrent() != null) { | ||
UI.getCurrent().access(() -> UIFactory.notificationError("An internal error has occurred." + | ||
"Contact support for assistance.")); | ||
Notification notification = UIFactory.notificationError( | ||
errorEvent.getThrowable().getMessage()); | ||
UI.getCurrent().add(notification); | ||
notification.open(); | ||
} | ||
} | ||
|
||
@Override | ||
public int setErrorParameter(BeforeEnterEvent event, | ||
ErrorParameter<SamicException> | ||
parameter) { | ||
getElement().setText(parameter.getCaughtException().getMessage()); | ||
logger.info("Error: {}", parameter.getException().getMessage()); | ||
return HttpServletResponse.SC_INTERNAL_SERVER_ERROR; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters