2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.rest;
24 * A custom exception class.
29 public class RESTException extends Exception {
30 private static final long serialVersionUID = -6874042744590915838L;
32 private final int statusCode;
35 private final String errorMessage;
39 * @see Exception#RESTException(String)
41 public RESTException(final String errorMessage) {
42 this(-1, errorMessage);
47 * @see Exception#RESTException(Throwable)
49 public RESTException(final Throwable cause) {
52 this.errorMessage = cause.getMessage();
56 * Creates a RESTException with the specified status code and error
59 * @param statusCode http status code
60 * @param errorMessage http error message
62 public RESTException(final int statusCode, final String errorMessage) {
63 super(statusCode + ":" + errorMessage);
64 this.statusCode = statusCode;
65 this.errorMessage = errorMessage;
69 * Gets the status code or -1 if none has been set.
73 public int getStatusCode() {
74 return this.statusCode;
78 * Gets the error message.
80 * @return error message
82 public String getErrorMessage() {
83 return this.errorMessage;