Refactoring error handler
Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -40,27 +40,26 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void error(final ErrorEvent event) {
|
public void error(final ErrorEvent event) {
|
||||||
|
|
||||||
final Optional<Page> originError = getPageOriginError(event);
|
|
||||||
final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
|
final HawkbitErrorNotificationMessage message = buildNotification(getRootExceptionFrom(event));
|
||||||
|
|
||||||
if (!originError.isPresent()) {
|
|
||||||
HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(),
|
|
||||||
Type.HUMANIZED_MESSAGE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event instanceof ConnectorErrorEvent) {
|
if (event instanceof ConnectorErrorEvent) {
|
||||||
final Connector connector = ((ConnectorErrorEvent) event).getConnector();
|
final Connector connector = ((ConnectorErrorEvent) event).getConnector();
|
||||||
if (connector instanceof UI) {
|
if (connector instanceof UI) {
|
||||||
((UI) connector).access(() -> message.show(originError.get()));
|
final UI uiInstance = (UI) connector;
|
||||||
|
uiInstance.access(() -> message.show(uiInstance.getPage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message.show(originError.get());
|
|
||||||
|
final Optional<Page> originError = getPageOriginError(event);
|
||||||
|
if (originError.isPresent()) {
|
||||||
|
message.show(originError.get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HawkbitErrorNotificationMessage.show(message.getCaption(), message.getDescription(), Type.HUMANIZED_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Throwable getRootExceptionFrom(final ErrorEvent event) {
|
private static Throwable getRootExceptionFrom(final ErrorEvent event) {
|
||||||
|
|
||||||
return getRootCauseOf(event.getThrowable());
|
return getRootCauseOf(event.getThrowable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,16 +83,18 @@ public class HawkbitUIErrorHandler extends DefaultErrorHandler {
|
|||||||
return Optional.absent();
|
return Optional.absent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to build a notification based on an exception.
|
||||||
|
*
|
||||||
|
* @param ex
|
||||||
|
* the throwable
|
||||||
|
* @return a hawkbit error notification message
|
||||||
|
*/
|
||||||
protected HawkbitErrorNotificationMessage buildNotification(final Throwable ex) {
|
protected HawkbitErrorNotificationMessage buildNotification(final Throwable ex) {
|
||||||
|
LOG.error("Error in UI: ", ex);
|
||||||
log(ex);
|
|
||||||
|
|
||||||
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
final I18N i18n = SpringContextHelper.getBean(I18N.class);
|
||||||
return new HawkbitErrorNotificationMessage(STYLE, i18n.get("caption.error"),
|
return new HawkbitErrorNotificationMessage(STYLE, i18n.get("caption.error"),
|
||||||
i18n.get("message.error.temp", ex.getClass().getSimpleName()), false);
|
i18n.get("message.error.temp", ex.getClass().getSimpleName()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void log(final Throwable exception) {
|
|
||||||
LOG.error("Error in UI: ", exception);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user