Exception: ECMBlockchain::Error
- Inherits:
-
StandardError
- Object
- StandardError
- ECMBlockchain::Error
- Defined in:
- lib/ecm-blockchain-api/errors.rb
Direct Known Subclasses
BadGateway, BadRequest, Forbidden, GatewayTimeout, InternalServerError, NotAcceptable, NotFound, PaymentRequired, RequestEntityTooLarge, ServerError, ServiceUnavailable, TimeoutError, TooManyRequests, Unauthorized, UnprocessableEntityError
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message: "", code: nil, details: nil, name: nil) ⇒ ECMBlockchain::Error
constructor
Initializes a new Error object.
Constructor Details
#initialize(message: "", code: nil, details: nil, name: nil) ⇒ ECMBlockchain::Error
Initializes a new Error object
23 24 25 26 27 28 29 |
# File 'lib/ecm-blockchain-api/errors.rb', line 23 def initialize(message: "", code: nil, details: nil, name: nil) super() @code = code @details = details @name = name end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/ecm-blockchain-api/errors.rb', line 3 def code @code end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
3 4 5 |
# File 'lib/ecm-blockchain-api/errors.rb', line 3 def details @details end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ecm-blockchain-api/errors.rb', line 3 def name @name end |
Class Method Details
.raise_error(response) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ecm-blockchain-api/errors.rb', line 5 def self.raise_error(response) klass = ERROR_CLASS_MAP[response.code] || self res = response.body res = '{}' if res == '' err = JSON.parse(res).deep_symbolize_keys[:error] raise klass.new( message: err[:message] || response.headers["status"], code: err[:statusCode] || response.code, details: err[:details], name: klass.to_s ) end |