Class JsonRpcError

java.lang.Object
org.moera.lib.jsonrpc.JsonRpcError

public class JsonRpcError extends Object
Represents an error object in the JSON-RPC protocol. JSON-RPC defines error objects for various failure scenarios, and this class provides a structured way to define and retrieve error codes and messages based on the protocol.

Instances of this class include predefined standard errors, as well as the ability to define custom errors by providing a code and a message.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final JsonRpcError
    Represents a standard JSON-RPC error indicating a "bulk error".
    static final int
    Represents the lower bound for custom-defined server error codes in the JSON-RPC protocol.
    static final int
    Upper bound for custom server error codes in the JSON-RPC protocol.
    static final JsonRpcError
    Represents a standard JSON-RPC error indicating that the error encountered during the execution of a request was not specifically handled.
    static final JsonRpcError
    Represents a predefined error in the JSON-RPC protocol indicating an internal server error.
    static final JsonRpcError
    Represents a standard JSON-RPC error indicating that the received request is invalid.
    static final JsonRpcError
    Represents a JSON-RPC predefined error indicating that the requested method does not exist or is unavailable.
    static final JsonRpcError
    Represents a standard JSON-RPC error that occurs when the parameters provided to a JSON-RPC method are invalid or do not meet the method's requirements.
    static final JsonRpcError
    Represents a JSON-RPC success indicator with no error.
    static final JsonRpcError
    Represents the JSON-RPC standard error for parsing issues.
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonRpcError(int code, String message)
    Constructs a new JsonRpcError instance with the specified error code and message.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Retrieves the code associated with the JSON-RPC error.
    Retrieves the message associated with the JSON-RPC error.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OK

      public static final JsonRpcError OK
      Represents a JSON-RPC success indicator with no error.
    • PARSE_ERROR

      public static final JsonRpcError PARSE_ERROR
      Represents the JSON-RPC standard error for parsing issues.
    • INVALID_REQUEST

      public static final JsonRpcError INVALID_REQUEST
      Represents a standard JSON-RPC error indicating that the received request is invalid. This error typically occurs when the JSON sent by the client is not a valid JSON object, or when the provided JSON does not conform to the structure expected by the JSON-RPC protocol.
    • METHOD_NOT_FOUND

      public static final JsonRpcError METHOD_NOT_FOUND
      Represents a JSON-RPC predefined error indicating that the requested method does not exist or is unavailable.
    • METHOD_PARAMS_INVALID

      public static final JsonRpcError METHOD_PARAMS_INVALID
      Represents a standard JSON-RPC error that occurs when the parameters provided to a JSON-RPC method are invalid or do not meet the method's requirements.
    • INTERNAL_ERROR

      public static final JsonRpcError INTERNAL_ERROR
      Represents a predefined error in the JSON-RPC protocol indicating an internal server error.

      This error is used as a catch-all for cases where no other specific error codes apply, and is typically returned when an unexpected condition is encountered on the server.

    • ERROR_NOT_HANDLED

      public static final JsonRpcError ERROR_NOT_HANDLED
      Represents a standard JSON-RPC error indicating that the error encountered during the execution of a request was not specifically handled. This error typically occurs when an unexpected or unhandled issue arises within the server's processing logic.

      It serves as a generic, non-specific error response in the JSON-RPC protocol when no other predefined error is applicable.

    • BULK_ERROR

      public static final JsonRpcError BULK_ERROR
      Represents a standard JSON-RPC error indicating a "bulk error". This error is typically used to signal issues occurring when processing multiple requests or operations in bulk.
    • CUSTOM_SERVER_ERROR_UPPER

      public static final int CUSTOM_SERVER_ERROR_UPPER
      Upper bound for custom server error codes in the JSON-RPC protocol. JSON-RPC allows the definition of custom server error codes within a specific range. This constant represents the upper limit of that range. Custom server error codes must fall between CUSTOM_SERVER_ERROR_LOWER and this value.
      See Also:
    • CUSTOM_SERVER_ERROR_LOWER

      public static final int CUSTOM_SERVER_ERROR_LOWER
      Represents the lower bound for custom-defined server error codes in the JSON-RPC protocol. Error codes in the range from CUSTOM_SERVER_ERROR_LOWER to CUSTOM_SERVER_ERROR_UPPER are reserved for non-standard, application-specific server errors.
      See Also:
  • Constructor Details

    • JsonRpcError

      public JsonRpcError(int code, String message)
      Constructs a new JsonRpcError instance with the specified error code and message. This class represents an error in the JSON-RPC protocol, where an error response includes a code indicating the error type and a message providing additional details.
      Parameters:
      code - the error code representing the type of error. It must be an integer and conform to the JSON-RPC specification or custom-defined codes.
      message - the error message providing details about the error. It must be a non-null and descriptive string to help identify the issue.
  • Method Details

    • getCode

      public int getCode()
      Retrieves the code associated with the JSON-RPC error.
      Returns:
      an integer representing the error code.
    • getMessage

      public String getMessage()
      Retrieves the message associated with the JSON-RPC error.
      Returns:
      the error message as a string.