Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use checkNested(Throwable) for req.next(Throwable) #6699

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -416,7 +416,7 @@ private void defaultHandler(Throwable t) {

@Override
public void next(Throwable t) {
checkNexted();
checkNexted(t);

nextNoCheck(t);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@
package io.helidon.webserver;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import io.helidon.common.context.Context;
Expand All @@ -28,6 +30,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -58,6 +61,33 @@ public void basicRouting() {
assertThat(checker.handlersInvoked(), is("namedUserHandler"));
}

@Test
public void nextedThrowable() {
final RoutingChecker checker = new RoutingChecker();
List<Exception> errors = new ArrayList<>();
Routing routing = Routing.builder()
.any("/", (req, resp) -> {
// make it "nexted"
req.next();
// propagate an exception while already "nexted"
req.next(new Exception("Booh"));
})
.get("/", (req, res) -> {
checker.handlerInvoked("terminalHandler");
})
.error(Exception.class, (req, res, ex) -> {
errors.add(ex);
})
.build();

routing.route(mockRequest("/", Http.Method.GET), mockResponse());
assertThat(checker.handlersInvoked(), is("terminalHandler"));
assertThat(errors.size(), is(1));
Exception ex = errors.get(0);
assertThat(ex.getCause(), is(notNullValue()));
assertThat(ex.getCause().getMessage(), is("Booh"));
}

@Test
public void routeFilters() {
final RoutingChecker checker = new RoutingChecker();
Expand Down