Class: JsonRpcObjects::V11::WD::Error

Inherits:
JsonRpcObjects::V10::Error show all
Includes:
Extensions
Defined in:
lib/json-rpc-objects/v11/wd/error.rb

Overview

Error description object class for ProcedureReturn.

Direct Known Subclasses

Alt::Error

Constant Summary collapse

VERSION =

Holds link to its version module.

JsonRpcObjects::V11::WD
DATA_MEMBER_NAME =

Indicates data member name.

:error

Instance Attribute Summary collapse

Attributes included from Extensions

#extensions

Attributes inherited from Generic::Object

#serializer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions

#[], #[]=, #method_missing

Methods inherited from Generic::Object

#initialize, parse, #serialize, #to_json, version

Constructor Details

This class inherits a constructor from JsonRpcObjects::Generic::Object

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JsonRpcObjects::V11::WD::Extensions

Instance Attribute Details

#codeInteger

Holds error code.

Returns:

  • (Integer)


54
55
56
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 54

def code
  @code
end

#dataObject

Holds error data.

Returns:

  • (Object)


70
71
72
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 70

def data
  @data
end

#messageString

Holds error message.

Returns:

  • (String)


62
63
64
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 62

def message
  @message
end

Class Method Details

.create(code, message, opts = { }) ⇒ V11::Error

Creates new one.

Parameters:

  • code (Numeric)

    od the error

  • message (String, Exception)

    of the error or exception object

  • opts (Hash) (defaults to: { })

    additional options

Returns:

  • (V11::Error)

    new error object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 83

def self.create(code, message, opts = { })
    data = {
        :code => code,
    }
    
    if message.kind_of? Exception
        data[:message] = message.message
        data[self::DATA_MEMBER_NAME] = message.backtrace
    else
        data[:message] = message
    end
    
    data.merge! opts
    return self::new(data)
end

Instance Method Details

#check!Object

Checks correctness of the data.



103
104
105
106
107
108
109
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 103

def check!
    self.normalize!

    if not @code.in? 100..999
        raise Exception::new("Code must be between 100 and 999 including them.")
    end
end

#outputHash

Renders data to output hash.

Returns:

  • (Hash)

    with data of error



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 116

def output
    self.check!
    data = {
        "name" => "JSONRPCError",
        "code" => @code,
        "message" => @message
    }
    
    if not @data.nil?
        data["error"] = @data
    end
    
    data.merge! @extensions.map_keys { |k| k.to_s }
    return data
end