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)


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

def code
  @code
end

#dataObject

Holds error data.

Returns:

  • (Object)


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

def data
  @data
end

#messageString

Holds error message.

Returns:

  • (String)


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

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



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

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.



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

def check!
    self.normalize!

    if not (100..999).include? @code
        raise JsonRpcObjects::Exceptions::InvalidCode::new("Code must be between 100 and 999 including them.")
    end
end

#outputHash

Renders data to output hash.

Returns:

  • (Hash)

    with data of error



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

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