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());
}
}
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();
}
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);
}
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);
}
}
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);
}
}
Aggregations