Why does Mutiny Multi does not throw any Exception if an execution fails?

108 views Asked by At

I have a method which either returns the data Multi<CustomClass> or if there is any issues during the execution then it throws the CustomException.

When I am using it via the Quarkus Rest API I am unable to throw the CustomException, even though I am able to print and get it in my terminal. How to throw an exception if there is a failure.

Following is the method which returns me with Multi<CustomClass>:

Multi<CustomClass> generator = CustomGenerator.generate(input);

If there is any Exception during the execution of CustomGenerator.generate then I want to throw the respective exception so I used something like this:

Multi<CustomClass> generator = CustomGenerator.generate(input)
    .onFailure().recoverWithMulti((failure) -> {
        throw new CustomException(failure.getMessage());
    });

This does not throw any Exception but if I print to my terminal then it shows the Exception message:

Multi<CustomClass> generator = CustomGenerator.generate(input)
    .onFailure().recoverWithMulti((failure) -> {
        System.out.println(failure.getMessage()); //displays the message but does not throw Exception
        throw new CustomException(failure.getMessage());
    });

How to ensure that the Exceptions are thrown correcty as per the standard and if there is no exception then continue further to pass the Multi<CustomClass> to next processing:

// Handle the success case here
System.out.println("Output Generation");
streamingOutput.setOutput(generator); //Accepts only the Multi<CustomClass>
return streamingOutput;

Unable to achieve this in Quarkus Rest API using the Mutiny Multi. I tried subscribing but if I do then even if there is no exception I do not get any output at all:

Multi<CustomClass> generator = CustomGenerator.generate(input)
    .onFailure().recoverWithMulti((failure) -> Multi.createFrom().failure(new CustomException(failure.getMessage())));

    generator.collect().asList().subscribe().with(
    items -> {
        // Handle the success case here
        streamingOutput.setOutput(generator); //Accepts only the Multi<CustomClass>
        System.out.println("Output Generation");
    },
    failure -> {
        // Handle the failure case here
        if (failure instanceof CustomException) {
            // Handle CustomException
            System.out.println("Failure : " + failure.getMessage());
        }
    }
);

return streamingEPCISDocument;

How can I throw Exception if execution of the CustomGenerator.generate(input) fails and if there is no Exception continue further with execution:

Multi<CustomClass> generator = CustomGenerator.generate(input);
// Handle the success case here
System.out.println("Output Generation");
streamingOutput.setOutput(generator); //Accepts only the Multi<CustomClass>
return streamingOutput;
0

There are 0 answers