2 * ============LICENSE_START===================================================
3 * Copyright (c) 2018 Amdocs
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.
16 * ============LICENSE_END=====================================================
18 package org.onap.sdnc.apps.pomba.networkdiscovery;
20 import javax.ws.rs.core.Response.Status;
22 public class ApplicationException extends Exception {
24 GENERAL_FAILURE("NET.0001", "An error occurred: %s"),
25 MISSING_PARAM("NET.0002", "Missing required parameter %s"),
26 UNAUTHORIZED("NET.0003", "Unauthorized");
28 private final String responseCode;
29 private final String message;
31 private Error(String responseCode, String message) {
32 this.responseCode = responseCode;
33 this.message = message;
36 public String getMessage(Object... args) {
37 return String.format(this.message, args);
40 public String getResponseCode() {
41 return this.responseCode;
45 private static final long serialVersionUID = -4874149714911165454L;
47 private final Status httpStatus;
48 private String responseCode;
50 public ApplicationException(String message) {
51 this(message, Status.INTERNAL_SERVER_ERROR);
54 public ApplicationException(Error errorCode, Status httpStatus, Object... args) {
55 super(errorCode.getMessage(args));
56 if (httpStatus == null) {
57 throw new NullPointerException("httpStatus");
60 this.responseCode = errorCode.getResponseCode();
61 this.httpStatus = httpStatus;
64 public ApplicationException(String message, Status httpStatus) {
66 if (httpStatus == null) {
67 throw new NullPointerException("httpStatus");
69 this.httpStatus = httpStatus;
72 public ApplicationException(String message, Exception cause) {
73 super(message, cause);
74 this.httpStatus = Status.INTERNAL_SERVER_ERROR;
77 public Status getHttpStatus() {
78 return this.httpStatus;
81 public String getResponseCode() {
82 return this.responseCode;