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;
25 import lombok.ToString;
26 import org.onap.policy.models.errors.concepts.ErrorResponse;
27 import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
28 import org.onap.policy.models.errors.concepts.ErrorResponseUtils;
31 * This class is a base exception from which all model exceptions are sub classes.
35 public class PfModelException extends Exception implements ErrorResponseInfo {
36 private static final long serialVersionUID = -8507246953751956974L;
38 // The error response of the exception
39 private final ErrorResponse errorResponse = new ErrorResponse();
41 // The object on which the exception was thrown
42 private final transient Object object;
45 * Instantiates a new model exception.
47 * @param statusCode the return code for the exception
48 * @param message the message on the exception
50 public PfModelException(final Response.Status statusCode, final String message) {
51 this(statusCode, message, null);
55 * Instantiates a new model exception.
57 * @param statusCode the return code for the exception
58 * @param message the message on the exception
59 * @param object the object that the exception was thrown on
61 public PfModelException(final Response.Status statusCode, final String message, final Object object) {
63 errorResponse.setResponseCode(statusCode);
64 ErrorResponseUtils.getExceptionMessages(errorResponse, this);
69 * Instantiates a new model exception.
71 * @param statusCode the return code for the exception
72 * @param message the message on the exception
73 * @param exception the exception that caused this exception
75 public PfModelException(final Response.Status statusCode, final String message, final Exception exception) {
76 this(statusCode, message, exception, null);
80 * Instantiates a new exception.
82 * @param statusCode the return code for the exception
83 * @param message the message on the exception
84 * @param exception the exception that caused this exception
85 * @param object the object that the exception was thrown on
87 public PfModelException(final Response.Status statusCode, final String message, final Exception exception,
88 final Object object) {
89 super(message, exception);
90 errorResponse.setResponseCode(statusCode);
91 ErrorResponseUtils.getExceptionMessages(errorResponse, this);