Skip to content

Commit c5a0420

Browse files
caaladorczp13
andauthored
fix: Update UI if custom errorHandler (#17504)
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>
1 parent b39cd4f commit c5a0420

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/internal/StateTree.java‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.vaadin.flow.function.SerializableConsumer;
3434
import com.vaadin.flow.internal.change.NodeChange;
3535
import com.vaadin.flow.internal.nodefeature.NodeFeature;
36+
import com.vaadin.flow.server.DefaultErrorHandler;
37+
import com.vaadin.flow.server.ErrorEvent;
3638
import com.vaadin.flow.server.VaadinSession;
3739
import com.vaadin.flow.server.communication.UidlWriter;
3840
import com.vaadin.flow.shared.Registration;
@@ -387,9 +389,20 @@ public void runExecutionsBeforeClientResponse() {
387389
}
388390
callbacks.stream().filter(entry -> entry.canExecute(getUI()))
389391
.forEach(entry -> {
390-
ExecutionContext context = new ExecutionContext(getUI(),
391-
entry.getStateNode().isClientSideInitialized());
392-
entry.getExecution().accept(context);
392+
try {
393+
ExecutionContext context = new ExecutionContext(
394+
getUI(), entry.getStateNode()
395+
.isClientSideInitialized());
396+
entry.getExecution().accept(context);
397+
} catch (Exception e) {
398+
if (getUI().getSession().getErrorHandler()
399+
.getClass()
400+
.equals(DefaultErrorHandler.class)) {
401+
throw e;
402+
}
403+
getUI().getSession().getErrorHandler()
404+
.error(new ErrorEvent(e));
405+
}
393406
});
394407
}
395408
}

‎flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ErrorHandlingView.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ public ErrorHandlingView() {
1111
throw new IllegalStateException(
1212
"Intentional fail in click handler");
1313
}));
14+
add(createButton("Throw exception in beforeClientResponse",
15+
"clientResponseButton", e -> {
16+
e.getSource().getUI().get().getInternals().getStateTree()
17+
.beforeClientResponse(getElement().getNode(),
18+
executionContext -> {
19+
throw new IllegalStateException(
20+
"Intentional fail in beforeClientResponse");
21+
});
22+
}));
1423
}
1524

1625
}

‎flow-tests/test-root-context/src/test/java/com/vaadin/flow/uitest/ui/ErrorHandlingIT.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,15 @@ public void exceptionInClickHandlerDoesNotCauseInternalError() {
1717
"An error occurred: java.lang.IllegalStateException: Intentional fail in click handler");
1818
}
1919

20+
@Test
21+
public void exceptionInBeforeClientResponseDoesNotCauseInternalError() {
22+
open();
23+
$(NativeButtonElement.class).id("clientResponseButton").click();
24+
25+
assertNoSystemErrors();
26+
27+
assertErrorReported(
28+
"An error occurred: java.lang.IllegalStateException: Intentional fail in beforeClientResponse");
29+
}
30+
2031
}

0 commit comments

Comments
 (0)