2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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=========================================================
21 package org.onap.policy.models.base;
23 import javax.ws.rs.core.Response;
26 import lombok.ToString;
28 import org.onap.policy.models.errors.concepts.ErrorResponse;
29 import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
30 import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
33 * This class is a base model run time exception from which all model run time exceptions are sub classes.
37 public class PfModelRuntimeException extends RuntimeException implements ErrorResponseInfo {
38 private static final long serialVersionUID = -8507246953751956974L;
40 // The error response of the exception
41 private final ErrorResponse errorResponse = new ErrorResponse();
43 // The object on which the exception was thrown
44 private final transient Object object;
47 * Instantiates a new model runtime exception.
49 * @param statusCode the return code for the exception
50 * @param message the message on the exception
52 public PfModelRuntimeException(final Response.Status statusCode, final String message) {
53 this(statusCode, message, null);
57 * Instantiates a new model runtime exception.
59 * @param statusCode the return code for the exception
60 * @param message the message on the exception
61 * @param object the object that the exception was thrown on
63 public PfModelRuntimeException(final Response.Status statusCode, final String message, final Object object) {
66 errorResponse.setResponseCode(statusCode);
67 ErrorResponseUtils.getExceptionMessages(errorResponse, this);
71 * Instantiates a new model runtime exception.
73 * @param statusCode the return code for the exception
74 * @param message the message on the exception
75 * @param exception the exception that caused this model exception
77 public PfModelRuntimeException(final Response.Status statusCode, final String message, final Exception exception) {
78 this(statusCode, message, exception, null);
82 * Instantiates a new model runtime exception.
84 * @param statusCode the return code for the exception
85 * @param message the message on the exception
86 * @param exception the exception that caused this model exception
87 * @param object the object that the exception was thrown on
89 public PfModelRuntimeException(final Response.Status statusCode, final String message, final Exception exception,
90 final Object object) {
91 super(message, exception);
93 errorResponse.setResponseCode(statusCode);
94 ErrorResponseUtils.getExceptionMessages(errorResponse, this);