2

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?

Marc
  • 1,900
  • 14
  • 22

1 Answers1

1

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();
            }
        })
}
geoand
  • 60,071
  • 24
  • 172
  • 190