Skip to content

Commit

Permalink
Make per class @ServerExceptionMapper work with Mutiny response types
Browse files Browse the repository at this point in the history
Relates to: quarkusio#15673
  • Loading branch information
geoand committed Mar 16, 2021
1 parent a08cede commit 7064dc7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ public void testResourceWithExceptionMapper() {
.then().statusCode(500);
}

@Test
public void testResourceWithExceptionMapperAndUniResponse() {
RestAssured.get("/first/uni?name=IllegalState")
.then().statusCode(409);
RestAssured.get("/first/uni?name=IllegalArgument")
.then().statusCode(409);
RestAssured.get("/first/uni?name=My")
.then().statusCode(410).body(Matchers.equalTo("/first/uni->uni"));
RestAssured.get("/first/uni?name=MyOther")
.then().statusCode(411);
RestAssured.get("/first/uni?name=Uni")
.then().statusCode(412).body(Matchers.equalTo("/first/uni->uni"));
RestAssured.get("/first/uni?name=Other")
.then().statusCode(500);
}

@Test
public void testResourceWithoutExceptionMapper() {
RestAssured.get("/second")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ public String throwsVariousExceptions(@RestQuery String name) {
throw new RuntimeException();
}

@GET
@Path("uni")
@Produces("text/plain")
public Uni<String> uni(@RestQuery String name) {
Exception e = new RuntimeException();
if (name.startsWith("IllegalArgument")) {
e = new IllegalArgumentException();
} else if (name.startsWith("IllegalState")) {
e = new IllegalStateException("IllegalState");
} else if (name.startsWith("MyOther")) {
e = new MyOtherException();
} else if (name.startsWith("My")) {
e = new MyException();
} else if (name.startsWith("Uni")) {
e = new UniException();
}
return Uni.createFrom().failure(e);
}

@ServerExceptionMapper({ IllegalStateException.class, IllegalArgumentException.class })
public Response handleIllegal() {
return Response.status(409).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public synchronized void resume(Throwable throwable) {
resume((Executor) null);
}

public synchronized void resume(Throwable throwable, boolean keepTarget) {
handleException(throwable, keepTarget);
resume((Executor) null);
}

public synchronized void resume(Executor executor) {
if (running) {
this.executor = executor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected void handleException(ResteasyReactiveRequestContext requestContext, Th
log.error("Exception in SSE server handling, impossible to send it to client", t);
} else {
// we can go through the abort chain
requestContext.resume(t);
requestContext.resume(t, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void accept(Object v) {
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) {
requestContext.resume(t);
requestContext.resume(t, true);
}
});
}
Expand Down

0 comments on commit 7064dc7

Please sign in to comment.