summaryrefslogtreecommitdiffstats
path: root/cps-nf-proxy-rest/src
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-03-11 10:34:35 +0000
committerNiamh Core <niamh.core@est.tech>2021-03-11 17:34:34 +0000
commit3de08a9590b5590d5961d9e4047751760043307e (patch)
tree48554368a834e60b5934e0fc74eb57bc4d03ec6e /cps-nf-proxy-rest/src
parent99f0f0be7cc540dd32aacc770468d73444bcfb18 (diff)
Exception stack trace is exposed
Issue-ID: CPS-249 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I1e03c17364c925c6f976f2147cb17f8ac26ba995
Diffstat (limited to 'cps-nf-proxy-rest/src')
-rw-r--r--cps-nf-proxy-rest/src/main/java/org/onap/cps/nfproxy/rest/exceptions/NfProxyRestExceptionHandler.java25
1 files changed, 9 insertions, 16 deletions
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 96a1cb267d..ebcb0135ef 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;
@@ -39,6 +38,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice(assignableTypes = {NfProxyController.class})
public class NfProxyRestExceptionHandler {
+ private static final String checkLogsForDetails = "Check logs for details.";
+
/**
* Default exception handler.
*
@@ -53,26 +54,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() :
+ checkLogsForDetails);
return new ResponseEntity<>(errorMessage, status);
}
-
- private static String extractDetails(final CpsException exception) {
- return exception.getCause() == null
- ? exception.getDetails()
- : ExceptionUtils.getStackTrace(exception.getCause());
- }
}