From a9a5058eb33eda7d273bab5122736266980c99dc Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Mon, 18 Oct 2021 17:12:39 +0100 Subject: Refactor GlobalControllerExceptionHandler Issue-ID: POLICY-3530 Change-Id: Ib33daf8491c1bf96460b424e8b0da228d65e571a Signed-off-by: FrancescoFioraEst --- .../runtime/main/web/GlobalControllerExceptionHandler.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'runtime-controlloop/src/main') diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java index d093c677f..fd493fd89 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/web/GlobalControllerExceptionHandler.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.controlloop.runtime.main.web; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; +import org.onap.policy.clamp.controlloop.models.rest.RestUtils; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.springframework.http.ResponseEntity; @@ -39,9 +40,7 @@ public class GlobalControllerExceptionHandler { */ @ExceptionHandler(ControlLoopException.class) public ResponseEntity handleBadRequest(ControlLoopException ex) { - var resp = new SimpleResponse(); - resp.setErrorDetails(ex.getErrorResponse().getErrorMessage()); - return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp); + return RestUtils.toSimpleResponse(ex); } /** @@ -52,9 +51,7 @@ public class GlobalControllerExceptionHandler { */ @ExceptionHandler(PfModelRuntimeException.class) public ResponseEntity handleBadRequest(PfModelRuntimeException ex) { - var resp = new SimpleResponse(); - resp.setErrorDetails(ex.getErrorResponse().getErrorMessage()); - return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp); + return RestUtils.toSimpleResponse(ex); } /** @@ -65,9 +62,6 @@ public class GlobalControllerExceptionHandler { */ @ExceptionHandler(PfModelException.class) public ResponseEntity handleBadRequest(PfModelException ex) { - var resp = new SimpleResponse(); - resp.setErrorDetails(ex.getErrorResponse().getErrorMessage()); - return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp); + return RestUtils.toSimpleResponse(ex); } - } -- cgit 1.2.3-korg