diff options
author | 2021-03-11 10:34:35 +0000 | |
---|---|---|
committer | 2021-03-29 10:57:12 +0000 | |
commit | 25c3c891404cb455047523322b6a040b2fb46218 (patch) | |
tree | 6827e045552e08a0972283d6db1a5326d70cd3c5 /cps-nf-proxy-rest | |
parent | 386658dbc8d2bf156a29537c5edb80ba574abb17 (diff) |
Exception stack trace is exposed
Issue-ID: CPS-249
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: I1e03c17364c925c6f976f2147cb17f8ac26ba995
(cherry picked from commit 3de08a9590b5590d5961d9e4047751760043307e)
Diffstat (limited to 'cps-nf-proxy-rest')
-rwxr-xr-x | cps-nf-proxy-rest/pom.xml | 4 | ||||
-rw-r--r-- | cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/exceptions/NfProxyRestExceptionHandler.java | 23 |
2 files changed, 7 insertions, 20 deletions
diff --git a/cps-nf-proxy-rest/pom.xml b/cps-nf-proxy-rest/pom.xml index b74cf6ec6..04dfa9a31 100755 --- a/cps-nf-proxy-rest/pom.xml +++ b/cps-nf-proxy-rest/pom.xml @@ -46,10 +46,6 @@ <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> <!-- T E S T D E P E N D E N C I E S --> <dependency> <groupId>org.codehaus.groovy</groupId> diff --git a/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/exceptions/NfProxyRestExceptionHandler.java b/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/exceptions/NfProxyRestExceptionHandler.java index 96a1cb267..9a90f55de 100644 --- a/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/exceptions/NfProxyRestExceptionHandler.java +++ b/cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/exceptions/NfProxyRestExceptionHandler.java @@ -22,7 +22,6 @@ package org.onap.cps.nfproxy.rest.exceptions; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.onap.cps.nfproxy.rest.controller.NfProxyController; import org.onap.cps.nfproxy.rest.model.ErrorMessage; import org.onap.cps.spi.exceptions.CpsException; @@ -53,26 +52,18 @@ public class NfProxyRestExceptionHandler { @ExceptionHandler({CpsException.class}) public static ResponseEntity<Object> handleAnyOtherCpsExceptions(final CpsException exception) { - return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), extractDetails(exception)); + return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); } private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final Exception exception) { - return buildErrorResponse(status, exception.getMessage(), ExceptionUtils.getStackTrace(exception)); - } - - private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final String message, - final String details) { - log.error("An error has occurred : {} Status: {} Details: {}", message, status, details); + if (exception.getCause() != null || !(exception instanceof CpsException)) { + log.error("Exception occurred", exception); + } final ErrorMessage errorMessage = new ErrorMessage(); errorMessage.setStatus(status.toString()); - errorMessage.setMessage(message); - errorMessage.setDetails(details); + errorMessage.setMessage(exception.getMessage()); + errorMessage.setDetails(exception instanceof CpsException ? ((CpsException) exception).getDetails() : + "Check logs for details."); return new ResponseEntity<>(errorMessage, status); } - - private static String extractDetails(final CpsException exception) { - return exception.getCause() == null - ? exception.getDetails() - : ExceptionUtils.getStackTrace(exception.getCause()); - } } |