Skip to content

Commit 2b3f11f

Browse files
committed
problem throwing StatusCodeException when there's an error handler fix jooby-project#1349
1 parent 865614b commit 2b3f11f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ private Route defineRoute(@Nonnull String method, @Nonnull String pattern,
385385
@Nonnull public Router start(@Nonnull Jooby owner) {
386386
if (err == null) {
387387
err = ErrorHandler.DEFAULT;
388+
} else {
389+
err = err.then(ErrorHandler.DEFAULT);
388390
}
389391
renderer.add(MessageEncoder.TO_STRING);
390392
ExecutionMode mode = owner.getExecutionMode();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.jooby;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class Issue1349 {
8+
9+
public static class App1349 extends Jooby {
10+
{
11+
error(IllegalAccessException.class, ((ctx, cause, statusCode) -> {
12+
ctx.setResponseCode(statusCode);
13+
ctx.send(cause.getMessage());
14+
}));
15+
get("/1349", ctx ->
16+
something()
17+
);
18+
get("/1349/iae", ctx ->
19+
throwsIAE()
20+
);
21+
}
22+
23+
private String throwsIAE() throws IllegalAccessException {
24+
throw new IllegalAccessException("no-access");
25+
}
26+
27+
public String something() {
28+
throw new StatusCodeException(StatusCode.UNAUTHORIZED, "test");
29+
}
30+
31+
}
32+
33+
@Test
34+
public void issue1349() {
35+
new JoobyRunner(App1349::new)
36+
.ready(client -> {
37+
client.get("/1349", rsp -> {
38+
assertEquals(401, rsp.code());
39+
});
40+
client.get("/1349/iae", rsp -> {
41+
assertEquals(500, rsp.code());
42+
assertEquals("no-access", rsp.body().string());
43+
});
44+
});
45+
}
46+
}

0 commit comments

Comments
 (0)