diff --git a/src/main/java/io/cryostat/rules/Rules.java b/src/main/java/io/cryostat/rules/Rules.java index 6acc0b9e6..d1df06e0f 100644 --- a/src/main/java/io/cryostat/rules/Rules.java +++ b/src/main/java/io/cryostat/rules/Rules.java @@ -39,6 +39,7 @@ import org.jboss.resteasy.reactive.RestQuery; import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder; +import org.jboss.resteasy.reactive.server.ServerExceptionMapper; @Path("/api/v2/rules") public class Rules { @@ -81,6 +82,14 @@ public RestResponse create(Rule rule) { .build(); } + @ServerExceptionMapper + public RestResponse mapException(RuleExistsException e) { + return ResponseBuilder.create( + Response.Status.CONFLICT, + V2Response.json(Response.Status.CONFLICT, e.getMessage())) + .build(); + } + @Transactional @PATCH @RolesAllowed("write") @@ -147,7 +156,7 @@ public RestResponse delete(@RestPath String name, @RestQuery boolean return RestResponse.ok(V2Response.json(Response.Status.OK, null)); } - static class RuleExistsException extends ClientErrorException { + public class RuleExistsException extends ClientErrorException { RuleExistsException(String ruleName) { super( "Rule with name "