1 /*
2  * RpcError.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 package org.rstudio.core.client.jsonrpc;
17 
18 import com.google.gwt.core.client.JavaScriptObject;
19 import com.google.gwt.json.client.JSONObject;
20 import com.google.gwt.json.client.JSONValue;
21 
22 public class RpcError extends JavaScriptObject
23 {
create(int code, String message)24    public static final native RpcError create(int code, String message) /*-{
25       var error = new Object();
26       error.code = code;
27       error.message = message;
28       return error;
29    }-*/;
30 
RpcError()31    protected RpcError()
32    {
33    }
34 
35    // no error
36    public final static int SUCCESS = 0;
37 
38    // couldn't connect to service (method not executed)
39    public final static int CONNECTION_ERROR = 1;
40 
41    // service is currently unavailable
42    public final static int UNAVAILABLE = 2;
43 
44    // not authorized to access service or method (method not executed)
45    public final static int UNAUTHORIZED = 3;
46 
47    // provided client id is invalid (method not executed)
48    public final static int INVALID_CLIENT_ID = 4;
49 
50    // protocol errors (method not executed)
51    public final static int PARSE_ERROR = 5;
52    public final static int INVALID_REQUEST = 6;
53    public final static int METHOD_NOT_FOUND = 7;
54    public final static int PARAM_MISSING = 8;
55    public final static int PARAM_TYPE_MISMATCH = 9;
56    public final static int PARAM_INVALID = 10;
57    public final static int METHOD_UNEXEPECTED = 11;
58    public final static int INVALID_CLIENT_VERSION = 12;
59    public final static int SERVER_OFFLINE = 13;
60    public final static int INVALID_SESSION = 14;
61    public final static int MAX_SESSIONS_REACHED = 15;
62    public final static int MAX_USERS_REACHED = 16;
63 
64    // this session is a launcher session and the launch parameters need to be resent to implicitly relaunch the session
65    public final static int LAUNCH_PARAMETERS_MISSING = 17;
66 
67    // execution error (method was executed and returned known error state)
68    public final static int EXECUTION_ERROR = 100;
69 
70    // transmission error (application state indeterminate)
71    public final static int TRANSMISSION_ERROR = 200;
72 
getCode()73    public final native int getCode() /*-{
74       return this.code;
75    }-*/;
76 
getMessage()77    public final native String getMessage() /*-{
78       return this.message;
79    }-*/;
80 
getRedirectUrl()81    public final native String getRedirectUrl() /*-{
82       return this.redirect_url;
83    }-*/;
84 
getError()85    public final native RpcUnderlyingError getError() /*-{
86       return this.error;
87    }-*/;
88 
getClientInfo()89    public final JSONValue getClientInfo()
90    {
91       return new JSONObject(this).get("client_info");
92    }
93 
getEndUserMessage()94    public final String getEndUserMessage()
95    {
96       RpcUnderlyingError underlyingError = getError();
97       if (underlyingError != null)
98          return underlyingError.getMessage();
99       else
100          return getMessage();
101    }
102 }
103