quarkusresteasyreactivemutiny

How to convert a Uni<Void> response to a "not found" in Quarkus Resteasy Reactive?


Given an endpoint like that:

@GET
@Path("{id}")
public Uni<Stuff> getSomeStuff(@PathParam("id") int id) {
   return someService.fetchStuff(id);
}

When someService.fetchStuff(id) returns an Uni<Void> the endpoints returns an empty HTTP response with status 204 (not found).

How can I get the endpoint to send an HTTP response with status 404 (not found) in this case?


Solution

  • You can do something like this:

    @GET
    @Path("{id}")
    public Uni<RestResponse<Stuff>> getSomeStuff(@PathParam("id") int id) {
       return someService.fetchStuff(id).onItem().transform(s -> {
                if (test(s)) {
                    return RestResponse.ok(s);
                } else {
                    return RestResponse.notFound();
                }
            })
    }