eclipse-ee4j / eclipse-ee4j/jersey
CompletionStage behaviour in case of WebApplicationException
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I'm faced with a case where I'm not sure what the behavior should be.
When throwing a WebApplicationException, jersey automatically translates the exception in its corresponding response.
While using CompletionStage, I would expect the behavior to be similar. In practice, it translates to an internal server error. The JAX-RS specification is not very clear on that particular point
Consider the following case :
```
@GET
@Path("failAsync/later")
public CompletionStage failAsyncLater() {
CompletableFuture fail = new CompletableFuture<>();
failLater(fail, new IllegalStateException("Uh-oh"));
// We re-throw a WebApplicationException .exceptionally.
// This has the side effect of wrapping the WebApplicationException inside a CompletionException
return fail.exceptionally(ex -> {
throw new WebApplicationException("OOPS", Response.Status.NOT_ACCEPTABLE.getStatusCode());
});
}
private void failLater(CompletableFuture cf, Throwable t) {
new Thread(() -> {
try {
Thread.sleep(500);
cf.completeExceptionally(t);
}
catch (InterruptedException ex) {
// nothing to do, let the thread die.
}
).start();
}
```
I would actually expect to get an HTTP 406, instead of a 500.
Can you clarify the current behavior and the way this kind of error is supposed to be handled ?
Thanks a lot!
Contributor guide
Research direction
Start with the failAsyncLater CompletionStage example and reproduce how the wrapped WebApplicationException is translated. Read Jersey's asynchronous exception-handling path and the relevant JAX-RS specification text; done means the current behavior and the expected handling of the HTTP 406 response are clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100