Skip to content

Commit

Permalink
add error mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Jan 23, 2024
1 parent 7f10508 commit 64b3d68
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/io/cryostat/rules/Rules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -81,6 +82,14 @@ public RestResponse<V2Response> create(Rule rule) {
.build();
}

@ServerExceptionMapper
public RestResponse<V2Response> mapException(RuleExistsException e) {
return ResponseBuilder.create(
Response.Status.CONFLICT,
V2Response.json(Response.Status.CONFLICT, e.getMessage()))
.build();
}

@Transactional
@PATCH
@RolesAllowed("write")
Expand Down Expand Up @@ -147,7 +156,7 @@ public RestResponse<V2Response> 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 "
Expand Down

0 comments on commit 64b3d68

Please sign in to comment.