Exception: Peddler::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Peddler::Error
- Defined in:
- lib/peddler/error.rb
Direct Known Subclasses
Peddler::Errors::AccessDenied, Peddler::Errors::InvalidGrant, Peddler::Errors::InvalidInput, Peddler::Errors::InvalidRequest, Peddler::Errors::NotFound, Peddler::Errors::QuotaExceeded, Peddler::Errors::Unauthorized, Peddler::Errors::UnsupportedGrantType
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(msg = nil, response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(msg = nil, response = nil) ⇒ Error
Returns a new instance of Error.
64 65 66 67 |
# File 'lib/peddler/error.rb', line 64 def initialize(msg = nil, response = nil) @response = response super(msg) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/peddler/error.rb', line 7 def response @response end |
Class Method Details
.build(response) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/peddler/error.rb', line 11 def build(response) payload = begin JSON.parse(response) rescue JSON::ParserError parse_xml_error(response) end if payload.key?("error") class_name = normalize_class_name(payload["error"]) = payload["error_description"] elsif payload.key?("errors") class_name = normalize_class_name(payload.dig("errors", 0, "code")) = payload.dig("errors", 0, "message") elsif payload.key?("Code") class_name = payload["Code"] = payload["Message"] else return end klass = if Errors.const_defined?(class_name) Errors.const_get(class_name) else Errors.const_set( class_name, Class.new(Error), ) end klass.new(, response) rescue NameError # Do nothing if code cannot be converted to a class name end |