4c50304c60895a0644ffafeae410fa7e774a125b
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.v3po.translate.v3po.util;
18
19 import com.google.common.annotations.Beta;
20 import com.google.common.base.Preconditions;
21 import javax.annotation.Nonnull;
22
23 /**
24  * Thrown when Vpp jAPI method invocation failed.
25  */
26 @Beta
27 public class VppApiInvocationException extends Exception {
28     private final String methodName;
29     private final int ctxId;
30     private final int errorCode;
31
32     /**
33      * Constructs an VppApiInvocationFailedException with the specified api method name and error code.
34      *
35      * @param methodName method name that failed to invoke
36      * @param ctxId      api request context identifier
37      * @param errorCode  negative error code value associated with this failure
38      * @throws NullPointerException     if apiMethodName is null
39      * @throws IllegalArgumentException if errorCode is nonnegative
40      */
41     public VppApiInvocationException(@Nonnull final String methodName, final int ctxId, final int errorCode) {
42         super(String.format("vppApi.%s failed with error code: %d (ctxId=%d) ", methodName, errorCode, ctxId));
43         this.methodName = Preconditions.checkNotNull(methodName, "apiMethodName is null!");
44         this.ctxId = ctxId;
45         Preconditions.checkArgument(errorCode < 0);
46         this.errorCode = errorCode;
47     }
48
49     /**
50      * Returns method name that failed to invoke.
51      *
52      * @return method name
53      */
54     public String getMethodName() {
55         return methodName;
56     }
57
58     /**
59      * Returns api request context identifier.
60      *
61      * @return value of context identifier
62      */
63     public int getCtxId() {
64         return ctxId;
65     }
66
67     /**
68      * Returns the error code associated with this failure.
69      *
70      * @return a negative integer error code
71      */
72     public int getErrorCode() {
73         return errorCode;
74     }
75 }