Search in sources :

Example 1 with ErrorStateRenderer

use of com.vaadin.flow.router.internal.ErrorStateRenderer in project flow by vaadin.

the class Router method handleExceptionNavigation.

private int handleExceptionNavigation(UI ui, Location location, Exception exception) {
    ErrorParameter<?> errorParameter = new ErrorParameter<>(exception, exception.getMessage());
    Optional<Class<? extends Component>> navigationTarget = getRegistry().getErrorNavigationTarget(errorParameter.getException());
    if (navigationTarget.isPresent()) {
        ErrorStateRenderer handler = new ErrorStateRenderer(new NavigationStateBuilder().withTarget(navigationTarget.get()).build());
        ErrorNavigationEvent navigationEvent = new ErrorNavigationEvent(this, location, ui, NavigationTrigger.PROGRAMMATIC, errorParameter);
        return handler.handle(navigationEvent);
    } else {
        throw new RuntimeException(errorParameter.getCustomMessage(), errorParameter.getException());
    }
}
Also used : ErrorStateRenderer(com.vaadin.flow.router.internal.ErrorStateRenderer) Component(com.vaadin.flow.component.Component)

Example 2 with ErrorStateRenderer

use of com.vaadin.flow.router.internal.ErrorStateRenderer in project flow by vaadin.

the class JavaScriptBootstrapUI method handleExceptionNavigation.

private boolean handleExceptionNavigation(Location location, Exception exception) {
    Optional<ErrorTargetEntry> maybeLookupResult = getInternals().getRouter().getErrorNavigationTarget(exception);
    if (maybeLookupResult.isPresent()) {
        ErrorTargetEntry lookupResult = maybeLookupResult.get();
        ErrorParameter<?> errorParameter = new ErrorParameter<>(lookupResult.getHandledExceptionType(), exception, exception.getMessage());
        ErrorStateRenderer errorStateRenderer = new ErrorStateRenderer(new NavigationStateBuilder(getInternals().getRouter()).withTarget(lookupResult.getNavigationTarget()).build());
        ErrorNavigationEvent errorNavigationEvent = new ErrorNavigationEvent(getInternals().getRouter(), location, this, NavigationTrigger.CLIENT_SIDE, errorParameter);
        errorStateRenderer.handle(errorNavigationEvent);
    } else {
        throw new RuntimeException(exception);
    }
    return isPostponed();
}
Also used : NavigationStateBuilder(com.vaadin.flow.router.NavigationStateBuilder) ErrorTargetEntry(com.vaadin.flow.router.internal.ErrorTargetEntry) ErrorNavigationEvent(com.vaadin.flow.router.ErrorNavigationEvent) ErrorStateRenderer(com.vaadin.flow.router.internal.ErrorStateRenderer) ErrorParameter(com.vaadin.flow.router.ErrorParameter)

Example 3 with ErrorStateRenderer

use of com.vaadin.flow.router.internal.ErrorStateRenderer in project flow by vaadin.

the class JavaScriptBootstrapUI method handleErrorNavigation.

private void handleErrorNavigation(Location location) {
    NavigationState errorNavigationState = getInternals().getRouter().resolveRouteNotFoundNavigationTarget().orElse(getDefaultNavigationError());
    ErrorStateRenderer errorStateRenderer = new ErrorStateRenderer(errorNavigationState);
    NotFoundException notFoundException = new NotFoundException("Couldn't find route for '" + location.getPath() + "'");
    ErrorParameter<NotFoundException> errorParameter = new ErrorParameter<>(NotFoundException.class, notFoundException);
    ErrorNavigationEvent errorNavigationEvent = new ErrorNavigationEvent(getInternals().getRouter(), location, this, NavigationTrigger.CLIENT_SIDE, errorParameter);
    errorStateRenderer.handle(errorNavigationEvent);
}
Also used : NavigationState(com.vaadin.flow.router.NavigationState) ErrorNavigationEvent(com.vaadin.flow.router.ErrorNavigationEvent) NotFoundException(com.vaadin.flow.router.NotFoundException) ErrorStateRenderer(com.vaadin.flow.router.internal.ErrorStateRenderer) ErrorParameter(com.vaadin.flow.router.ErrorParameter)

Example 4 with ErrorStateRenderer

use of com.vaadin.flow.router.internal.ErrorStateRenderer in project flow by vaadin.

the class BeforeEvent method rerouteToError.

/**
 * Reroute to error target for given exception with given custom message.
 *
 * @param exception
 *            exception to get error target for
 * @param customMessage
 *            custom message to send to error target
 */
public void rerouteToError(Exception exception, String customMessage) {
    Optional<ErrorTargetEntry> maybeLookupResult = getSource().getErrorNavigationTarget(exception);
    if (maybeLookupResult.isPresent()) {
        ErrorTargetEntry lookupResult = maybeLookupResult.get();
        rerouteTargetState = new NavigationStateBuilder(ui.getInternals().getRouter()).withTarget(lookupResult.getNavigationTarget()).build();
        rerouteTarget = new ErrorStateRenderer(rerouteTargetState);
        errorParameter = new ErrorParameter<>(lookupResult.getHandledExceptionType(), exception, customMessage);
    } else {
        throw new RuntimeException(customMessage, exception);
    }
}
Also used : ErrorTargetEntry(com.vaadin.flow.router.internal.ErrorTargetEntry) ErrorStateRenderer(com.vaadin.flow.router.internal.ErrorStateRenderer)

Example 5 with ErrorStateRenderer

use of com.vaadin.flow.router.internal.ErrorStateRenderer in project flow by vaadin.

the class Router method handleExceptionNavigation.

private int handleExceptionNavigation(UI ui, Location location, Exception exception, NavigationTrigger trigger, JsonValue state) {
    Optional<ErrorTargetEntry> maybeLookupResult = getErrorNavigationTarget(exception);
    if (maybeLookupResult.isPresent()) {
        ErrorTargetEntry lookupResult = maybeLookupResult.get();
        ErrorParameter<?> errorParameter = new ErrorParameter<>(lookupResult.getHandledExceptionType(), exception, exception.getMessage());
        ErrorStateRenderer handler = new ErrorStateRenderer(new NavigationStateBuilder(this).withTarget(lookupResult.getNavigationTarget()).build());
        ErrorNavigationEvent navigationEvent = new ErrorNavigationEvent(this, location, ui, trigger, errorParameter, state);
        return handler.handle(navigationEvent);
    } else {
        throw new RuntimeException(exception);
    }
}
Also used : ErrorTargetEntry(com.vaadin.flow.router.internal.ErrorTargetEntry) ErrorStateRenderer(com.vaadin.flow.router.internal.ErrorStateRenderer)

Aggregations

ErrorStateRenderer (com.vaadin.flow.router.internal.ErrorStateRenderer)5 ErrorTargetEntry (com.vaadin.flow.router.internal.ErrorTargetEntry)3 ErrorNavigationEvent (com.vaadin.flow.router.ErrorNavigationEvent)2 ErrorParameter (com.vaadin.flow.router.ErrorParameter)2 Component (com.vaadin.flow.component.Component)1 NavigationState (com.vaadin.flow.router.NavigationState)1 NavigationStateBuilder (com.vaadin.flow.router.NavigationStateBuilder)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1