Java 17 / Spring 6 / Spring Boot 3 Upgrade
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / exception / PolicyApiRuntimeException.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
4  * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
5  * Modifications Copyright (C) 2023 Nordix Foundation.
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.api.main.exception;
24
25 import java.io.Serial;
26 import java.util.UUID;
27 import lombok.Getter;
28 import org.onap.policy.models.errors.concepts.ErrorResponse;
29
30 /**
31  * This runtime exception will be called if a runtime error occurs when using policy api.
32  */
33 @Getter
34 public class PolicyApiRuntimeException extends RuntimeException {
35
36     @Serial
37     private static final long serialVersionUID = -8507246953751956974L;
38
39     private final UUID requestId;
40     private final ErrorResponse errorResponse;
41
42     /**
43      * Instantiates a new policy api runtime exception with a message.
44      *
45      * @param message the message
46      */
47     public PolicyApiRuntimeException(final String message) {
48         super(message);
49         this.requestId = null;
50         this.errorResponse = null;
51     }
52
53     /**
54      * Instantiates a new policy api runtime exception with a message and a caused by exception.
55      *
56      * @param message the message
57      * @param exp the exception that caused this exception to be thrown
58      */
59     public PolicyApiRuntimeException(final String message, final Exception exp) {
60         super(message, exp);
61         this.requestId = null;
62         this.errorResponse = null;
63     }
64
65     /**
66      * Instantiates a new policy api runtime exception with requestId, errorResponse object
67      * along with message and a caused by exception.
68      *
69      * @param message the message
70      * @param cause the exception that caused this exception to be thrown
71      * @param requestId request identifier
72      * @param errorResponse error response object
73      */
74     public PolicyApiRuntimeException(final String message, final Throwable cause,
75                                      final ErrorResponse errorResponse, final UUID requestId) {
76         super(message, cause);
77         this.requestId = requestId;
78         this.errorResponse = errorResponse;
79     }
80 }