992df5fd6a5b56729607411b969b42a9b9784c37
[so.git] / adapters / mso-adapter-utils / src / main / java / org / onap / so / cloudify / exceptions / MsoCloudifyException.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.cloudify.exceptions;
22
23 import org.onap.so.openstack.exceptions.MsoException;
24 import org.onap.so.openstack.exceptions.MsoExceptionCategory;
25
26 /**
27  * OpenStack exception.
28  */
29 public class MsoCloudifyException extends MsoException
30 {
31         
32         /**
33      * Serialization id.
34      */
35     private static final long serialVersionUID = 3313636124141766495L;
36     
37     private int statusCode;
38         private String statusMessage;
39         private String errorDetail;
40         private boolean pendingWorkflow;
41
42         /**
43          * Constructor to create a new MsoOpenstackException instance
44          * @param code the error code
45          * @param message the error message
46          * @param detail error details
47          */
48         public MsoCloudifyException (int code, String message, String detail) {
49                 // Set the detailed error as the Exception 'message'
50                 super(detail);
51                 super.category = MsoExceptionCategory.OPENSTACK;
52                 
53                 this.statusCode = code;
54                 this.statusMessage = message;
55                 this.errorDetail = detail;
56                 this.pendingWorkflow = false;
57         }
58         
59         /**
60          * Constructor to propagate the caught exception (mostly for stack trace)
61      * @param code the error code
62      * @param message the error message
63      * @param detail error details
64          * @param e the cause
65          */
66         public MsoCloudifyException (int code, String message, String detail, Exception e) {
67                 // Set the detailed error as the Exception 'message'
68                 super(detail, e);
69                 super.category = MsoExceptionCategory.OPENSTACK;
70                 
71                 this.statusCode = code;
72                 this.statusMessage = message;
73                 this.errorDetail = detail;
74                 this.pendingWorkflow = false;
75         }
76         
77         public void setPendingWorkflow (boolean pendingWorkflow) {
78                 this.pendingWorkflow = pendingWorkflow;
79         }
80         
81         @Override
82         public String toString () {
83                 String error = "" + statusCode + " " + statusMessage + ": " + errorDetail + (pendingWorkflow ? " [workflow pending]" : "");
84                 return error;
85         }
86 }