Exception: CarrotRpc::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/carrot_rpc/error.rb

Overview

Error raised by an RpcServer method to signal that a JSON RPC 2.0 Response Error object should be the reply.

Defined Under Namespace

Modules: Code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, message:, data: nil) ⇒ Error

Returns a new instance of Error.

Parameters:

  • code (Integer)

    A Number that indicates the error type that occurred. Favor using the predefined codes.

  • message (String)

    A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.

  • data (Object, nil) (defaults to: 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.).



22
23
24
25
26
# File 'lib/carrot_rpc/error.rb', line 22

def initialize(code:, message:, data: nil)
  @code = code
  @data = data
  super(message)
end

Instance Attribute Details

#codeInteger (readonly)

Returns A Number that indicates the error type that occurred. Some codes are predefined.

Returns:

  • (Integer)

    A Number that indicates the error type that occurred. Some codes are predefined.



8
9
10
# File 'lib/carrot_rpc/error.rb', line 8

def code
  @code
end

#dataObject? (readonly)

Returns 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.).

Returns:

  • (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.).



13
14
15
# File 'lib/carrot_rpc/error.rb', line 13

def data
  @data
end

Instance Method Details

#serialized_messageHash{code: String, message: String}, Hash{code: String, data: Object, message: String}

A properly formatted JSON RPC Error object.

Returns:

  • (Hash{code: String, message: String}, Hash{code: String, data: Object, message: String})


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/carrot_rpc/error.rb', line 31

def serialized_message
  serialized = {
    code: code,
    message: message
  }

  if data
    serialized[:data] = data
  end

  serialized
end