X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-rest%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Frest%2Fexceptions%2FCpsRestExceptionHandler.java;h=0437e70fe52c0fec79cf14061ab105b342d5c006;hb=63be201ed60ca0d0b16ebe5a1a9d3a8e3f7b8482;hp=7719417c136309a2b115561e5825ac7af40e0982;hpb=840eecbf7210d0433d94da895a3a11b97d3a4e6f;p=cps.git diff --git a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java index 7719417c13..0437e70fe5 100755 --- a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java +++ b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Pantheon.tech + * Copyright (C) 2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +25,7 @@ import org.onap.cps.rest.controller.AdminRestController; import org.onap.cps.rest.controller.DataRestController; import org.onap.cps.rest.controller.QueryRestController; import org.onap.cps.rest.model.ErrorMessage; +import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.spi.exceptions.CpsAdminException; import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.spi.exceptions.CpsPathException; @@ -42,8 +44,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; QueryRestController.class}) public class CpsRestExceptionHandler { - private static final String CHECK_LOGS_FOR_DETAILS = "Check logs for details."; - private CpsRestExceptionHandler() { } @@ -54,8 +54,7 @@ public class CpsRestExceptionHandler { * @return response with response code 500. */ @ExceptionHandler - public static ResponseEntity handleInternalServerErrorExceptions( - final Exception exception) { + public static ResponseEntity handleInternalServerErrorExceptions(final Exception exception) { return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); } @@ -70,7 +69,7 @@ public class CpsRestExceptionHandler { return buildErrorResponse(HttpStatus.NOT_FOUND, exception); } - @ExceptionHandler({DataInUseException.class}) + @ExceptionHandler({DataInUseException.class, AlreadyDefinedException.class}) public static ResponseEntity handleDataInUseException(final CpsException exception) { return buildErrorResponse(HttpStatus.CONFLICT, exception); } @@ -88,7 +87,7 @@ public class CpsRestExceptionHandler { errorMessage.setStatus(status.toString()); errorMessage.setMessage(exception.getMessage()); errorMessage.setDetails(exception instanceof CpsException ? ((CpsException) exception).getDetails() : - CHECK_LOGS_FOR_DETAILS); + "Check logs for details."); return new ResponseEntity<>(errorMessage, status); } }