1c28aa1f097912c6deb864906224d4cbd4514e54
[so.git] / bpmn / MSORESTClient / src / main / java / org / openecomp / mso / rest / RESTException.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.rest;
22
23 /**
24  * A custom exception class. 
25  *
26  * @version 1.0
27  *
28  */
29 public class RESTException extends Exception {
30     private static final long serialVersionUID = -6874042744590915838L;
31     // http status code
32     private final int statusCode;
33
34     // error message
35     private final String errorMessage;
36     
37     /**
38      * {@inheritDoc}
39      * @see Exception#RESTException(String)
40      */
41     public RESTException(final String errorMessage) {
42         this(-1, errorMessage);
43     }
44
45     /**
46      * {@inheritDoc}
47      * @see Exception#RESTException(Throwable)
48      */
49     public RESTException(final Throwable cause) {
50         super(cause);
51         this.statusCode = -1;
52         this.errorMessage = cause.getMessage();
53     }
54
55     /**
56      * Creates a RESTException with the specified status code and error 
57      * message.
58      *
59      * @param statusCode http status code
60      * @param errorMessage http error message
61      */
62     public RESTException(final int statusCode, final String errorMessage) {
63         super(statusCode + ":" + errorMessage);
64         this.statusCode = statusCode;
65         this.errorMessage = errorMessage;
66     }
67
68     /**
69      * Gets the status code or -1 if none has been set.
70      *
71      * @return status code
72      */
73     public int getStatusCode() {
74         return this.statusCode;
75     }
76
77     /**
78      * Gets the error message.
79      *
80      * @return error message
81      */
82     public String getErrorMessage() {
83         return this.errorMessage; 
84     }
85 }