From 17f65286e2658228d4f95eb3801d1cb7f28f6f07 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Mon, 5 Feb 2024 13:15:15 -0500 Subject: [PATCH] map clientExceptionErrors --- src/main/java/io/cryostat/rules/Rules.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/cryostat/rules/Rules.java b/src/main/java/io/cryostat/rules/Rules.java index 2ad91878a..36e4657de 100644 --- a/src/main/java/io/cryostat/rules/Rules.java +++ b/src/main/java/io/cryostat/rules/Rules.java @@ -83,10 +83,21 @@ public RestResponse create(Rule rule) { } @ServerExceptionMapper - public RestResponse mapException(RuleExistsException e) { + public RestResponse mapException(ClientErrorException e) { + if (e instanceof RuleExistsException) { + return ResponseBuilder.create( + Response.Status.CONFLICT, + V2Response.json(Response.Status.CONFLICT, e.getMessage())) + .build(); + } else if (e instanceof NotFoundException) { + return ResponseBuilder.create( + Response.Status.NOT_FOUND, + V2Response.json(Response.Status.NOT_FOUND, e.getMessage())) + .build(); + } return ResponseBuilder.create( - Response.Status.CONFLICT, - V2Response.json(Response.Status.CONFLICT, e.getMessage())) + Response.Status.BAD_REQUEST, + V2Response.json(Response.Status.BAD_REQUEST, e.getMessage())) .build(); }