Hello i'm trying to learn Quarkus but am unable to find out how to return a error message to the client
@POST
public Uni<Response> create(Fruit fruit) {
if (Fruit.find(fruit.name) != null) {
throw new WebApplicationException(fruit.name + " already exists", 422);
}
return Panache.<Fruit>withTransaction(fruit::persist)
.onItem()
.transform(inserted -> Response
.created(URI.create("/fruits" + inserted.id))
.build());
}
I have the following code block what i want is for the
fruit.name + " already exists
to be printed to the client when they try to POST. But I only get the 422 error code. How can I also send the message back to the client?
You can use
throw new WebApplicationException(Response.status(422).entity(fruit.name + " already exists").build())