Sha256: a20723a93e88707eefd062d1918c53408e3267e6689331dfea69f3f56969bf8f

Contents?: true

Size: 1.71 KB

Versions: 15

Compression:

Stored size: 1.71 KB

Contents

# Error raised by an {RpcServer} method to signal that a
# {http://www.jsonrpc.org/specification#error_object JSON RPC 2.0 Response Error object} should be the reply.
class CarrotRpc::Error < StandardError
  autoload :Code, "carrot_rpc/error/code"

  # @return [Integer]A Number that indicates the error type that occurred. Some codes are
  #   {http://www.jsonrpc.org/specification#error_object predefined}.
  attr_reader :code

  # @return [Object, nil] A Primitive or Structured value that contains additional information about the error.
  #   This may be omitted. The value of this member is defined by the Server (e.g. detailed error information,
  #   nested errors etc.).
  attr_reader :data

  # @param code [Integer] A Number that indicates the error type that occurred.  Favor using the
  #   {http://www.jsonrpc.org/specification#error_object predefined codes}.
  # @param message [String] A String providing a short description of the error. The message SHOULD be limited to a
  #   concise single sentence.
  # @param data [Object, nil] A Primitive or Structured value that contains additional information about the error.
  #   This may be omitted. The value of this member is defined by the Server (e.g. detailed error information,
  #   nested errors etc.).
  def initialize(code:, message:, data: nil)
    @code = code
    @data = data
    super(message)
  end

  # A properly formatted {http://www.jsonrpc.org/specification#error_object JSON RPC Error object}.
  #
  # @return [Hash{code: String, message: String}, Hash{code: String, data: Object, message: String}]
  def serialized_message
    serialized = {
      code: code,
      message: message
    }

    if data
      serialized[:data] = data
    end

    serialized
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
carrot_rpc-1.2.1 lib/carrot_rpc/error.rb
carrot_rpc-1.2.0 lib/carrot_rpc/error.rb
carrot_rpc-1.1.0 lib/carrot_rpc/error.rb
carrot_rpc-1.0.0 lib/carrot_rpc/error.rb
carrot_rpc-0.8.0 lib/carrot_rpc/error.rb
carrot_rpc-0.7.1 lib/carrot_rpc/error.rb
carrot_rpc-0.7.0 lib/carrot_rpc/error.rb
carrot_rpc-0.6.0 lib/carrot_rpc/error.rb
carrot_rpc-0.5.1 lib/carrot_rpc/error.rb
carrot_rpc-0.5.0 lib/carrot_rpc/error.rb
carrot_rpc-0.4.1 lib/carrot_rpc/error.rb
carrot_rpc-0.4.0 lib/carrot_rpc/error.rb
carrot_rpc-0.3.0 lib/carrot_rpc/error.rb
carrot_rpc-0.2.3 lib/carrot_rpc/error.rb
carrot_rpc-0.2.3.pre lib/carrot_rpc/error.rb