Exception: Dimelo::CCP::API::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Dimelo::CCP::API::Error
- Defined in:
- lib/dimelo/ccp/api/error.rb
Instance Attribute Summary collapse
-
#original_exception ⇒ Object
Returns the value of attribute original_exception.
Class Method Summary collapse
-
.from(method, path, http_status, body) ⇒ Object
Public : Return specific Exceptions if defined.
Instance Attribute Details
#original_exception ⇒ Object
Returns the value of attribute original_exception.
4 5 6 |
# File 'lib/dimelo/ccp/api/error.rb', line 4 def original_exception @original_exception end |
Class Method Details
.from(method, path, http_status, body) ⇒ Object
Public : Return specific Exceptions if defined
Returns :
-
DefinedError descendant exception (DomainNotFoundError,…) if status & name matches declared DefinedError child
-
BaseError if status and name does not match any declared Error
-
Error if body cannot be json parsed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dimelo/ccp/api/error.rb', line 12 def self.from(method, path, http_status, body) json = Dimelo::CCP::API.decode_json(body).symbolize_keys! name = json.delete(:error) status = json.delete(:status) = json.delete(:message) if klass = DefinedError.descendants.find { |error| error.status == status && error.name == name} klass.new else BaseError.new(name, status, ) end rescue ActiveSupport::JSON.parse_error new("#{method.to_s.upcase} #{path} - #{http_status} #{body}") end |