-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Quarkus Reactive Mutiny - Composite Exception encapsulation on Runtime Exceptions and @ExceptionHandler #11557
Comments
/cc @cescoffier |
Cc @jponge |
Would you mind reformatting the issue? The code is not always in Markdown code blocks, and not indented which makes it hard to read. |
Done @jponge , is it better now ? |
Better, although you could have syntax highlighting with ```java fenced blocks 😉 I'll have a look at the issue |
On having something similar to On using On exceptions being composite: this is expected when multiple failures need to be reported. |
@jponge : if i am throwing one xyz runtime exception from down my chain why should it be wrapped as a CompositeException... can it not be simply thrown up the reactive chain as xyz runtimeException. ? I will raise a separate issue for @ExceptionHandler. I am coming from a context that if i have multiple APIs need same exceptions handled , it need not be code in the controller reactive chain but should be in a separate method annotated. |
CompositeExceptions are only created if your first failure (the RuntimeException) triggers a second failure. So, you have at least 2 failures. Another situation where Note that you should be able to retrieve the initial "main" failure using |
About |
I am only throwing a single XYZ Runtime Exception and no other failure is triggered. When the exception lands in the Controller its a Composite Exception with one cause which I think is an unnecessary thing to parse exceptions especially if its just one exception thrown. |
Could you help me out with a sample documentation on this please ? Would like to see how its done. |
Can you provide the code? What do you call controller? But, as an example, if you use
Check the following example: In this example, the route checks for the exception type and build the expected response (404, 402...). |
@cescoffier . Thanks for ur help and inputs .Yes I can provide code. And if you can help me out in correcting it so that I can get only one RuntimeException that would be useful. The controller code remains the same as presented earlier. The controller calls the service which pretty much calls the DAO layer. The service code is just a delegate at the moment and has no exception handling there. @Override
@Timeout(100)
@CircuitBreaker(requestVolumeThreshold = 5, delay = 1000, failOn = {
PAInternalServerException.class,
CompositeException.class,
RuntimeException.class
})
public Uni < String > create( << SomePOJO >> somePOJO) {
//Setting POJO to first insert query
.....
//Setting POJO to second insert query
........
return SqlClientHelper.inTransactionUni(mySQLPool, tx ->{
Uni < RowSet < Row >> insertQueryOne = tx.query( << insert query one >> ).execute();
Uni < RowSet < Row >> insertQueryTwo = tx.query( << insert query two >> ).execute();
return insertQueryOne.and(insertQueryTwo).onItem().ignore().andContinueWithNull();
}).map(response -> <<some string>> )
.onItemOrFailure()
.apply((id, throwable) ->{
if (id != null) {
return id;
}
if (throwable != null) {
// this is the exception thrown which i am interested in catching it directly at the controller.
throw new PAInternalServerException("Something wrong happened while inserting data");
}
return "";
});
} For the routes example , it looks better than what I have coded. There is now a common block which I can use as an interceptor to create HTTPResponse for exceptions using RoutingContext object. Couple of things : a) Is there a feature enhancement in pipeline that there would be support for exception based methods instead one common error method so that we wouldnt need to do unneccessary instanceofs like from line 99 to line 105 in your code snippet? Example annotation enhancement:
b) When I tried using the |
Thanks for the code, which explain why you get a Here is the code from Mutiny: @Override
public void onFailure(Throwable failure) {
if (!subscriber.isCancelledOrDone()) {
O outcome;
try {
outcome = mapper.apply(null, failure);
// We cannot call onItem here, as if onItem would throw an exception
// it would be caught and onFailure would be called. This would be illegal.
} catch (Throwable e) { // NOSONAR
// Be sure to not call the mapper again with the failure.
subscriber.onFailure(new CompositeException(failure, e)); // <--- That's where the CompositeException gets created.
return;
}
subscriber.onItem(outcome);
}
} The So, I would rewrite your code as follows:
Instead of using About having the list of exceptions in failure handlers, that's a good idea. I will let @mkouba comment on this. |
Thanks @cescoffier . that works . @mkouba : Is there a plan on adding this feature for exception type based method resolvers in the next 1,2 or 3 month roadmap for vertx-io web ?
|
@harry9111985 I like your proposal. We could even consider something like: @Route(path = "/*", type = FAILURE)
void handleExceptionTypeY(DEFRuntimeException exception, RoutingContext context) {} I will create a separate issue. We could target Quarkus 1.9. |
@mkouba : that works for me too ... thanks for putting it in the enhancement roadmap.. the code will get more cleaner :-) |
Hey @mkouba .. is this feature going to be part of the Quarkus 1.9 milestone ? I dont see 1.9 milestone attached for the same . |
@harry9111985 yes, I forgot to create the issue: #12249 |
Works well @mkouba . Quick question before I close the issue . Does this segregation of exception blocks work for non-reactive Vertx Web Routes or this capability is only implemented for Reactive Mutiny Vertx Routes ? |
I'm not quite sure I understand your question but a failure handler declared via |
Thanks . Thats what I was looking for . You answered my question . I am closing this issue . |
Description
I am evaluating quarkus 1.6 and reactive Mutiny for reactive routes. My experience with quarkus mutiny exception handling is not so great . The current problem I have is if I throw a RuntimeException down in the service layer or data layer . The exception gets encapsulated as a CompositeException with a list of causes where one of the causes is the the RuntimeException thrown. This means that I have to always Parse the CompositeException to retrieve the actual exception which I have thrown to determine the HTTP status response ( of whether to throw a 500 or 422 or something else) .
Code Snippet - Current :
Code Snippet - Expected :
Implementation ideas
Can we have something similar to spring webflux , where if a RuntimeException is thrown from the data layer
a) Exactly same exception is captured in the error block of the controller class without needing to parse an encapsulated exception .
b) The Spring Boot framework has a @ControllerAdvice and @ExceptionHandler annotations to cleanly segregating the class for handling exceptions and controller. Can the same be available for Quarkus Reactive Mutiny extension.
c) The Spring boot framework has ServerWebExchange object which we can use as a context object to pass custom context . The good thing of this serverwebExchange object is that it is injected automatically as part of @ExceptionHandler Method making it easy to pass Context objects to exception handling methods . Can we have something similar in quarkus / reactive mutiny ?
(If you have any implementation ideas, they can go here, however please note that all design change proposals should be posted to the Quarkus developer mailing list (or the corresponding Google Group; see the decisions process document for more information).
The text was updated successfully, but these errors were encountered: