Exception: Peddler::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Peddler::Error
- Defined in:
- lib/peddler/error.rb
Direct Known Subclasses
Defined Under Namespace
Classes: InvalidInput, NotFound, QuotaExceeded, Unauthorized
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.
26 27 28 29 |
# File 'lib/peddler/error.rb', line 26 def initialize(msg = nil, response = nil) @response = response super(msg) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/peddler/error.rb', line 10 def response @response end |
Class Method Details
.build(response) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/peddler/error.rb', line 14 def build(response) error = JSON.parse(response).dig("errors").first class_name = error.dig("code") = error.dig("message") klass = const_defined?(class_name) ? const_get(class_name) : const_set(class_name, Class.new(Error)) klass.new(, response) rescue NameError # Do nothing if code cannot be converted to a class name end |