9d20d33f9d979f1612b7f5e590d09694085f348d
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
6  * ======================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.exceptions;
22
23 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.ErrorResponse;
24 import org.springframework.http.HttpStatus;
25 import org.springframework.http.ResponseEntity;
26 import org.springframework.web.bind.annotation.ControllerAdvice;
27 import org.springframework.web.bind.annotation.ExceptionHandler;
28 import org.springframework.web.bind.annotation.RestController;
29 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
30
31 @ControllerAdvice(annotations = RestController.class)
32 public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
33
34     @ExceptionHandler(EntityNotFoundException.class)
35     public final ResponseEntity<Object> handleNotFoundException(EntityNotFoundException ex) {
36         return ErrorResponse.create(ex, HttpStatus.NOT_FOUND);
37     }
38
39     @ExceptionHandler(InvalidRequestException.class)
40     public final ResponseEntity<Object> handleInvalidRequestException(InvalidRequestException ex) {
41         return ErrorResponse.create(ex, HttpStatus.BAD_REQUEST);
42     }
43 }