Skip to content

Commit

Permalink
fix: Update UI if custom errorHandler (#17504)
Browse files Browse the repository at this point in the history
Enable update of UI for
beforeClientResponse
execution when a custom
ErrorHandler is set.

Fixes #17352

Co-authored-by: Peter Czuczor <61667986+czp13@users.noreply.github.com>
  • Loading branch information
2 people authored and vaadin-bot committed Sep 1, 2023
1 parent 0a422de commit fdb88b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
19 changes: 16 additions & 3 deletions flow-server/src/main/java/com/vaadin/flow/internal/StateTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.vaadin.flow.function.SerializableConsumer;
import com.vaadin.flow.internal.change.NodeChange;
import com.vaadin.flow.internal.nodefeature.NodeFeature;
import com.vaadin.flow.server.DefaultErrorHandler;
import com.vaadin.flow.server.ErrorEvent;
import com.vaadin.flow.server.VaadinSession;
import com.vaadin.flow.server.communication.UidlWriter;
import com.vaadin.flow.shared.Registration;
Expand Down Expand Up @@ -387,9 +389,20 @@ public void runExecutionsBeforeClientResponse() {
}
callbacks.stream().filter(entry -> entry.canExecute(getUI()))
.forEach(entry -> {
ExecutionContext context = new ExecutionContext(getUI(),
entry.getStateNode().isClientSideInitialized());
entry.getExecution().accept(context);
try {
ExecutionContext context = new ExecutionContext(
getUI(), entry.getStateNode()
.isClientSideInitialized());
entry.getExecution().accept(context);
} catch (Exception e) {
if (getUI().getSession().getErrorHandler()
.getClass()
.equals(DefaultErrorHandler.class)) {
throw e;
}
getUI().getSession().getErrorHandler()
.error(new ErrorEvent(e));
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ public ErrorHandlingView() {
throw new IllegalStateException(
"Intentional fail in click handler");
}));
add(createButton("Throw exception in beforeClientResponse",
"clientResponseButton", e -> {
e.getSource().getUI().get().getInternals().getStateTree()
.beforeClientResponse(getElement().getNode(),
executionContext -> {
throw new IllegalStateException(
"Intentional fail in beforeClientResponse");
});
}));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ public void exceptionInClickHandlerDoesNotCauseInternalError() {
"An error occurred: java.lang.IllegalStateException: Intentional fail in click handler");
}

@Test
public void exceptionInBeforeClientResponseDoesNotCauseInternalError() {
open();
$(NativeButtonElement.class).id("clientResponseButton").click();

assertNoSystemErrors();

assertErrorReported(
"An error occurred: java.lang.IllegalStateException: Intentional fail in beforeClientResponse");
}

}

0 comments on commit fdb88b2

Please sign in to comment.