Class: JsonRpcObjects::V11::WD::Error
- Inherits:
-
JsonRpcObjects::V10::Error
- Object
- Generic::Object
- Generic::Error
- JsonRpcObjects::V10::Error
- JsonRpcObjects::V11::WD::Error
- Includes:
- Extensions
- Defined in:
- lib/json-rpc-objects/v11/wd/error.rb
Overview
Error description object class for ProcedureReturn.
Direct Known Subclasses
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
-
#code ⇒ Integer
Holds error code.
-
#data ⇒ Object
readonly
Holds error data.
-
#message ⇒ String
Holds error message.
Attributes included from Extensions
Attributes inherited from Generic::Object
Class Method Summary collapse
-
.create(code, message, opts = { }) ⇒ V11::Error
Creates new one.
Instance Method Summary collapse
-
#check! ⇒ Object
Checks correctness of the data.
-
#output ⇒ Hash
Renders data to output hash.
Methods included from Extensions
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
#code ⇒ Integer
Holds error code.
53 54 55 |
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 53 def code @code end |
#data ⇒ Object
Holds error data.
69 70 71 |
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 69 def data @data end |
#message ⇒ String
Holds error message.
61 62 63 |
# File 'lib/json-rpc-objects/v11/wd/error.rb', line 61 def end |
Class Method Details
.create(code, message, opts = { }) ⇒ V11::Error
Creates new one.
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, , opts = { }) data = { :code => code, } if .kind_of? Exception data[:message] = . data[self::DATA_MEMBER_NAME] = .backtrace else data[: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 |
#output ⇒ Hash
Renders data to output hash.
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" => } if not @data.nil? data["error"] = @data end data.merge! JsonRpcObjects::Utils::Hash.map_keys(@extensions) { |k| k.to_s } return data end |