Exception: Chain::APIError
- Defined in:
- lib/chain/errors.rb
Overview
APIError describes errors that are codified by the Chain API. They have an error code, a message, and an optional detail field that provides additional context for the error.
Direct Known Subclasses
Constant Summary collapse
- RETRIABLE_STATUS_CODES =
[ 408, # Request Timeout 429, # Too Many Requests 500, # Internal Server Error 502, # Bad Gateway 503, # Service Unavailable 504, # Gateway Timeout 509, # Bandwidth Limit Exceeded ]
Instance Attribute Summary collapse
-
#chain_message ⇒ Object
Returns the value of attribute chain_message.
-
#code ⇒ Object
Returns the value of attribute code.
-
#data ⇒ Object
Returns the value of attribute data.
-
#detail ⇒ Object
Returns the value of attribute detail.
-
#request_id ⇒ Object
Returns the value of attribute request_id.
-
#response ⇒ Object
Returns the value of attribute response.
-
#temporary ⇒ Object
Returns the value of attribute temporary.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body, response) ⇒ APIError
constructor
A new instance of APIError.
- #retriable? ⇒ Boolean
Constructor Details
#initialize(body, response) ⇒ APIError
Returns a new instance of APIError.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chain/errors.rb', line 49 def initialize(body, response) self.code = body['code'] self. = body['message'] self.detail = body['detail'] self.temporary = body['temporary'] self.response = response self.request_id = response['Chain-Request-ID'] if response super self.class.(code, , detail, request_id) end |
Instance Attribute Details
#chain_message ⇒ Object
Returns the value of attribute chain_message.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def @chain_message end |
#code ⇒ Object
Returns the value of attribute code.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def code @code end |
#data ⇒ Object
Returns the value of attribute data.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def data @data end |
#detail ⇒ Object
Returns the value of attribute detail.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def detail @detail end |
#request_id ⇒ Object
Returns the value of attribute request_id.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def request_id @request_id end |
#response ⇒ Object
Returns the value of attribute response.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def response @response end |
#temporary ⇒ Object
Returns the value of attribute temporary.
47 48 49 |
# File 'lib/chain/errors.rb', line 47 def temporary @temporary end |
Class Method Details
.format_error_message(code, message, detail, request_id) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/chain/errors.rb', line 65 def self.(code, , detail, request_id) tokens = [] tokens << "Code: #{code}" if code.is_a?(String) && code.size > 0 tokens << "Message: #{}" tokens << "Detail: #{detail}" if detail.is_a?(String) && detail.size > 0 tokens << "Request-ID: #{request_id}" tokens.join(' ') end |
Instance Method Details
#retriable? ⇒ Boolean
61 62 63 |
# File 'lib/chain/errors.rb', line 61 def retriable? temporary || (response && RETRIABLE_STATUS_CODES.include?(Integer(response.code))) end |