I'm a bit lost when playing with Mutiny. I have a testfunction that Creates a String uni and when that is succesful I want that it return a 200 OK or when it fails(which it shouldn´t with this simple string creation) a 500 Internal Server Error for now.
I can get it to work by using the onItemOrOnFailure()
of mutiny but I'm trying to split up the handling of the success and failure scenario. I see my sout
of the onItem()
but I still get to the onFailure()
and get a 500 response in postman. Why do I go into the onFailure? What am I not understanding?
So I expect one or the other but I get into both.
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public Uni<RestResponse<?>> test() {
return Uni.createFrom().item("Hello world")
.onItem().transform(str -> {
var resp = RestResponse.ok(str);
System.out.println("In onItem");
return resp;
})
.onFailure().recoverWithNull().replaceWith(() -> {
System.out.println("In onFailure");
return RestResponse.status(500);
});
}