Class JSONRPC2Error
java.lang.Object
java.lang.Throwable
java.lang.Exception
com.thetransactioncompany.jsonrpc2.JSONRPC2Error
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
JSONRPC2ExtendedError
public class JSONRPC2Error extends Exception
Represents a JSON-RPC 2.0 error that occurred during the processing of a
request. This class is immutable.
The protocol expects error objects to be structured like this:
codeAn integer that indicates the error type.messageA string providing a short description of the error. The message should be limited to a concise single sentence.dataAdditional information, which may be omitted. Its contents is entirely defined by the application.
Note that the "Error" word in the class name was put there solely to
comply with the parlance of the JSON-RPC spec. This class doesn't inherit
from java.lang.Error. It's a regular subclass of
java.lang.Exception and, if thrown, it's to indicate a condition
that a reasonable application might want to catch.
This class also includes convenient final static instances for all standard JSON-RPC 2.0 errors:
PARSE_ERRORJSON parse error (-32700)INVALID_REQUESTInvalid JSON-RPC 2.0 Request (-32600)METHOD_NOT_FOUNDMethod not found (-32601)INVALID_PARAMSInvalid parameters (-32602)INTERNAL_ERRORInternal error (-32603)
Note that the range -32099..-32000 is reserved for additional server errors.
The mapping between JSON and Java entities (as defined by the underlying JSON Smart library):
true|false <---> java.lang.Boolean
number <---> java.lang.Number
string <---> java.lang.String
array <---> java.util.List
object <---> java.util.Map
null <---> null
- Author:
- Vladimir Dzhuvinov
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static JSONRPC2ErrorINTERNAL_ERRORInternal JSON-RPC 2.0 error (-32603).static JSONRPC2ErrorINVALID_PARAMSInvalid parameters error (-32602).static JSONRPC2ErrorINVALID_REQUESTInvalid JSON-RPC 2.0 request error (-32600).static JSONRPC2ErrorMETHOD_NOT_FOUNDMethod not found error (-32601).static JSONRPC2ErrorPARSE_ERRORJSON parse error (-32700). -
Constructor Summary
Constructors Constructor Description JSONRPC2Error(int code, String message)Creates a new JSON-RPC 2.0 error with the specified code and message.JSONRPC2Error(int code, String message, Object data)Creates a new JSON-RPC 2.0 error with the specified code, message and data. -
Method Summary
Modifier and Type Method Description static JSONRPC2ErrorappendMessage(JSONRPC2Error err, String apx)Deprecated.JSONRPC2ErrorappendMessage(String apx)Appends the specified string to the message of this JSON-RPC 2.0 error.booleanequals(Object object)OverridesObject.equals().intgetCode()Gets the JSON-RPC 2.0 error code.ObjectgetData()Gets the JSON-RPC 2.0 error data.static JSONRPC2ErrorsetData(JSONRPC2Error err, Object data)Deprecated.JSONRPC2ErrorsetData(Object data)Sets the specified data to a JSON-RPC 2.0 error.JsonObjecttoJSON()Deprecated.JsonObjecttoJSONObject()Returns a JSON object representation of this JSON-RPC 2.0 error.StringtoString()Serialises the error object to a JSON string.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Field Details
-
PARSE_ERROR
JSON parse error (-32700). -
INVALID_REQUEST
Invalid JSON-RPC 2.0 request error (-32600). -
METHOD_NOT_FOUND
Method not found error (-32601). -
INVALID_PARAMS
Invalid parameters error (-32602). -
INTERNAL_ERROR
Internal JSON-RPC 2.0 error (-32603).
-
-
Constructor Details
-
JSONRPC2Error
Creates a new JSON-RPC 2.0 error with the specified code and message. The optional data is omitted.- Parameters:
code- The error code (standard pre-defined or application-specific).message- The error message.
-
JSONRPC2Error
Creates a new JSON-RPC 2.0 error with the specified code, message and data.- Parameters:
code- The error code (standard pre-defined or application-specific).message- The error message.data- Optional error data, must map to a valid JSON type.
-
-
Method Details
-
appendMessage
Deprecated.Appends the specified string to the message of a JSON-RPC 2.0 error.- Parameters:
err- The JSON-RPC 2.0 error. Must not benull.apx- The string to append to the original error message.- Returns:
- A new JSON-RPC 2.0 error with the appended message.
-
setData
Deprecated.Sets the specified data to a JSON-RPC 2.0 error.- Parameters:
err- The JSON-RPC 2.0 error to have its data field set. Must not benull.data- Optional error data, must map to a valid JSON type.- Returns:
- A new JSON-RPC 2.0 error with the set data.
-
getCode
public int getCode()Gets the JSON-RPC 2.0 error code.- Returns:
- The error code.
-
getData
Gets the JSON-RPC 2.0 error data.- Returns:
- The error data,
nullif none was specified.
-
setData
Sets the specified data to a JSON-RPC 2.0 error.- Parameters:
data- Optional error data, must map to a valid JSON type.- Returns:
- A new JSON-RPC 2.0 error with the set data.
-
appendMessage
Appends the specified string to the message of this JSON-RPC 2.0 error.- Parameters:
apx- The string to append to the original error message.- Returns:
- A new JSON-RPC 2.0 error with the appended message.
-
toJSON
Deprecated.- See Also:
toJSONObject()
-
toJSONObject
Returns a JSON object representation of this JSON-RPC 2.0 error.- Returns:
- A JSON object representing this error object.
-
toString
Serialises the error object to a JSON string. -
equals
OverridesObject.equals().
-