Search in sources :

Example 1 with SystemError

use of com.vaadin.server.SystemError in project SORMAS-Project by hzi-braunschweig.

the class SormasErrorHandler method handleError.

public static void handleError(ErrorEvent event) {
    Logger logger = LoggerFactory.getLogger(SormasErrorHandler.class);
    final Throwable t = event.getThrowable();
    if (t instanceof SocketException) {
        // Most likely client browser closed socket
        logger.info("SocketException in CommunicationManager." + " Most likely client (browser) closed socket.");
        return;
    }
    ErrorMessage errorMessage = getErrorMessageForException(t);
    if (t != null) {
        // log the error or warning
        if (errorMessage instanceof SystemError) {
            logger.error(getMessage(t), t);
        } else {
            logger.warn(t.getMessage(), t);
        }
    }
    // finds the original source of the error/exception
    AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event);
    if (errorMessage != null && component != null) {
        // Shows the error in AbstractComponent
        if (errorMessage instanceof SystemError) {
            Notification.show(I18nProperties.getString(Strings.errorOccurred, I18nProperties.getString(Strings.errorOccurred)), I18nProperties.getString(Strings.errorWasReported), Notification.Type.ERROR_MESSAGE);
        } else {
            // to prevent the original message from appearing, if necessary
            if (component instanceof AbstractField<?>) {
                ((AbstractField<?>) component).setCurrentBufferedSourceException(null);
            }
            Notification notification = new Notification(I18nProperties.getString(Strings.errorProblemOccurred, I18nProperties.getString(Strings.errorProblemOccurred)), errorMessage.getFormattedHtmlMessage(), Notification.Type.WARNING_MESSAGE, true);
            notification.setDelayMsec(-1);
            notification.show(Page.getCurrent());
            component.setComponentError(errorMessage);
        }
    }
}
Also used : SocketException(java.net.SocketException) AbstractComponent(com.vaadin.ui.AbstractComponent) SystemError(com.vaadin.server.SystemError) AbstractField(com.vaadin.v7.ui.AbstractField) Logger(org.slf4j.Logger) ErrorMessage(com.vaadin.server.ErrorMessage) Notification(com.vaadin.ui.Notification)

Aggregations

ErrorMessage (com.vaadin.server.ErrorMessage)1 SystemError (com.vaadin.server.SystemError)1 AbstractComponent (com.vaadin.ui.AbstractComponent)1 Notification (com.vaadin.ui.Notification)1 AbstractField (com.vaadin.v7.ui.AbstractField)1 SocketException (java.net.SocketException)1 Logger (org.slf4j.Logger)1