/** * Call the session's {@link ErrorHandler}, if it has one, with the given * exception wrapped in an {@link ErrorEvent}. */ private void callErrorHandler(VaadinSession session, Exception e) { try { ErrorHandler errorHandler = ErrorEvent.findErrorHandler(session); if (errorHandler != null) { errorHandler.error(new ErrorEvent(e)); } } catch (Exception ex) { // Let's not allow error handling to cause trouble; log fails getLogger().log(Level.WARNING, "ErrorHandler call failed", ex); } }
/** * Handles exceptions thrown during the execution of this task. * * @since 7.1.8 * @param exception * the thrown exception. */ public void handleError(Exception exception) { try { exception = ErrorHandlingRunnable.processException(runnable, exception); if (exception != null) { ErrorEvent errorEvent = new ErrorEvent(exception); ErrorHandler errorHandler = ErrorEvent .findErrorHandler(session); if (errorHandler == null) { errorHandler = new DefaultErrorHandler(); } errorHandler.error(errorEvent); } } catch (Exception e) { getLogger().log(Level.SEVERE, e.getMessage(), e); } } }
listenerMethod.receiveEvent(event); } catch (Exception e) { errorHandler.error(new ErrorEvent(e));
private void onVaadinSessionStarted(VaadinRequest request, VaadinSession session) throws ServiceException { SessionInitEvent event = new SessionInitEvent(this, session, request); for (SessionInitListener listener : sessionInitListeners) { try { listener.sessionInit(event); } catch (Exception e) { /* * for now, use the session error handler; in the future, could * have an API for using some other handler for session init and * destroy listeners */ session.getErrorHandler().error(new ErrorEvent(e)); } } ServletPortletHelper.checkUiProviders(session, this); }
errorHandler.error(new ErrorEvent(t));
session.getErrorHandler().error(new ErrorEvent(e));
/** * Call the session's error handler. */ private void callErrorHandler(VaadinSession session, Exception e) { session.getErrorHandler().error(new ErrorEvent(e)); }
@Override public void handleError(Exception exception) { try { if (command instanceof ErrorHandlingCommand) { ErrorHandlingCommand errorHandlingCommand = (ErrorHandlingCommand) command; errorHandlingCommand.handleError(exception); } else { getSession().getErrorHandler() .error(new ErrorEvent(exception)); } } catch (Exception e) { getLogger().log(Level.SEVERE, e.getMessage(), e); } } });
/** * Handles exceptions thrown during the execution of this task. * * @param exception * the thrown exception. */ public void handleError(Exception exception) { try { if (command instanceof ErrorHandlingCommand) { ErrorHandlingCommand errorHandlingCommand = (ErrorHandlingCommand) command; errorHandlingCommand.handleError(exception); } else { ErrorEvent errorEvent = new ErrorEvent(exception); ErrorHandler errorHandler = ErrorEvent .findErrorHandler(session); if (errorHandler == null) { errorHandler = new DefaultErrorHandler(); } errorHandler.error(errorEvent); } } catch (Exception e) { getLogger().log(Level.SEVERE, e.getMessage(), e); } }
listenerMethod.receiveEvent(event); } catch (Exception e) { errorHandler.error(new ErrorEvent(e));
@Test public void testErrorMessageNotEmpty() { // GIVEN // WHEN errorHandler.error(new ErrorEvent(new RuntimeException(""))); // THEN assertEquals(1, messages.size()); Message message = messages.get(0); assertTrue(StringUtils.isNotBlank(message.getSubject())); assertTrue(StringUtils.isNotBlank(message.getMessage())); assertEquals(USER_NAME, message.getSender()); }
@Test public void testPreciseErrorMessage() { // GIVEN final String lessPreciseDetails = "An unsupported exception happened."; final String mostPreciseDetails = "Consciously throwing some unsupported exception for this test."; Exception e = new InvocationTargetException(new RuntimeException(lessPreciseDetails, new UnsupportedOperationException(mostPreciseDetails))); // WHEN errorHandler.error(new ErrorEvent(e)); // THEN assertEquals(1, messages.size()); Message message = messages.get(0); assertTrue(StringUtils.isNotBlank(message.getSubject())); assertTrue(StringUtils.isNotBlank(message.getMessage())); assertEquals(mostPreciseDetails, message.getSubject()); assertEquals(USER_NAME, message.getSender()); }
protected void processLinkHandlerRequest(VaadinRequest request) { WrappedSession wrappedSession = request.getWrappedSession(); //noinspection unchecked Map<String, String> params = (Map<String, String>) wrappedSession.getAttribute(LAST_REQUEST_PARAMS_ATTR); params = params != null ? params : Collections.emptyMap(); try { String action = (String) wrappedSession.getAttribute(LAST_REQUEST_ACTION_ATTR); LinkHandler linkHandler = AppBeans.getPrototype(LinkHandler.NAME, app, action, params); if (app.connection.isConnected() && linkHandler.canHandleLink()) { linkHandler.handle(); } else { app.linkHandler = linkHandler; } } catch (Exception e) { error(new com.vaadin.server.ErrorEvent(e)); } }
@Override protected void refresh(VaadinRequest request) { super.refresh(request); boolean sessionIsAlive = true; Connection connection = app.getConnection(); if (connection.isAuthenticated()) { // Ping middleware session if connected log.debug("Ping middleware session"); try { UserSession session = connection.getSession(); if (session instanceof ClientUserSession && ((ClientUserSession) session).isAuthenticated()) { userSessionService.getUserSession(session.getId()); } } catch (Exception e) { sessionIsAlive = false; app.exceptionHandlers.handle(new com.vaadin.server.ErrorEvent(e)); } if (sessionIsAlive) { events.publish(new SessionHeartbeatEvent(app)); } } if (sessionIsAlive) { events.publish(new UIRefreshEvent(this)); } }
vaadinSession.getErrorHandler().error(new ErrorEvent(t));