2 * Copyright © 2018-2019 Bell Canada Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.controllerblueprints.service.controller
19 import org.springframework.web.bind.annotation.RestControllerAdvice
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode
22 import org.onap.ccsdk.cds.controllerblueprints.service.common.ErrorMessage
23 import org.springframework.http.HttpStatus
24 import org.springframework.http.ResponseEntity
25 import org.springframework.web.bind.annotation.ExceptionHandler
28 * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right
34 @RestControllerAdvice("org.onap.ccsdk.cds.controllerblueprints")
35 open class ControllerBlueprintExeptionHandler {
38 fun ControllerBlueprintException(e: BluePrintException): ResponseEntity<ErrorMessage> {
39 var errorCode = ErrorCode.valueOf(e.code)
40 val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
41 return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))
45 fun ControllerBlueprintException(e: Exception): ResponseEntity<ErrorMessage> {
46 var errorCode = ErrorCode.GENERIC_FAILURE
47 val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message")
48 return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode))