2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.etsi.nfvo.ns.lcm.rest.exceptions;
22 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException;
23 import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400;
24 import org.onap.so.etsi.nfvo.ns.lcm.rest.NsLifecycleManagementController;
25 import org.springframework.http.HttpStatus;
26 import org.springframework.http.ResponseEntity;
27 import org.springframework.web.bind.annotation.ControllerAdvice;
28 import org.springframework.web.bind.annotation.ExceptionHandler;
31 * @author Waqas Ikram (waqas.ikram@est.tech)
34 @ControllerAdvice(assignableTypes = NsLifecycleManagementController.class)
35 public class NsLcmControllerExceptionHandler {
37 @ExceptionHandler(NsRequestProcessingException.class)
38 public ResponseEntity<InlineResponse400> handleNsRequestProcessingException(
39 final NsRequestProcessingException nsRequestProcessingException) {
40 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
41 .body(getInlineResponse400(nsRequestProcessingException));
44 @ExceptionHandler(Exception.class)
45 public ResponseEntity<InlineResponse400> handleNsRequestProcessingException(final Exception exception) {
46 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new InlineResponse400()
47 .status(HttpStatus.INTERNAL_SERVER_ERROR.value()).detail(exception.getMessage()));
50 private InlineResponse400 getInlineResponse400(final NsRequestProcessingException nsRequestProcessingException) {
51 if (nsRequestProcessingException.getProblemDetails() != null) {
52 return nsRequestProcessingException.getProblemDetails();
54 return new InlineResponse400().status(HttpStatus.INTERNAL_SERVER_ERROR.value())
55 .detail(nsRequestProcessingException.getMessage());