Exception: Telnyx::TelnyxError
- Inherits:
-
StandardError
- Object
- StandardError
- Telnyx::TelnyxError
- Defined in:
- lib/telnyx/errors.rb
Overview
TelnyxError is the base error from which all other more specific Telnyx errors derive.
Direct Known Subclasses
APIConnectionError, APIError, AuthenticationError, InvalidParametersError, InvalidRequestError, MethodNotSupportedError, PermissionError, RateLimitError, ResourceNotFoundError, ServiceUnavailableError, SignatureVerificationError, TimeoutError, UnsupportedMediaTypeError
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Full details for all errors returned in response.
-
#http_body ⇒ Object
readonly
Returns the value of attribute http_body.
-
#http_headers ⇒ Object
readonly
Returns the value of attribute http_headers.
-
#http_status ⇒ Object
readonly
Returns the value of attribute http_status.
-
#json_body ⇒ Object
readonly
equivalent to #data.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#response ⇒ Object
Response contains a TelnyxResponse object that has some basic information about the response that conveyed the error.
Instance Method Summary collapse
- #error_count ⇒ Object
-
#initialize(errors = nil, http_status: nil, http_body: nil, json_body: nil, http_headers: nil) ⇒ TelnyxError
constructor
Initializes a TelnyxError.
- #message ⇒ Object
- #other_errors_message ⇒ Object
- #stringify_errors(errors) ⇒ Object
- #stringify_hash(h) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(errors = nil, http_status: nil, http_body: nil, json_body: nil, http_headers: nil) ⇒ TelnyxError
Initializes a TelnyxError.
21 22 23 24 25 26 27 28 |
# File 'lib/telnyx/errors.rb', line 21 def initialize(errors = nil, http_status: nil, http_body: nil, json_body: nil, http_headers: nil) @http_status = http_status @http_body = http_body @http_headers = http_headers || {} @json_body = json_body @request_id = @http_headers[:request_id] @errors = stringify_errors(errors) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Full details for all errors returned in response
8 9 10 |
# File 'lib/telnyx/errors.rb', line 8 def errors @errors end |
#http_body ⇒ Object (readonly)
Returns the value of attribute http_body.
14 15 16 |
# File 'lib/telnyx/errors.rb', line 14 def http_body @http_body end |
#http_headers ⇒ Object (readonly)
Returns the value of attribute http_headers.
15 16 17 |
# File 'lib/telnyx/errors.rb', line 15 def http_headers @http_headers end |
#http_status ⇒ Object (readonly)
Returns the value of attribute http_status.
16 17 18 |
# File 'lib/telnyx/errors.rb', line 16 def http_status @http_status end |
#json_body ⇒ Object (readonly)
equivalent to #data
17 18 19 |
# File 'lib/telnyx/errors.rb', line 17 def json_body @json_body end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
18 19 20 |
# File 'lib/telnyx/errors.rb', line 18 def request_id @request_id end |
#response ⇒ Object
Response contains a TelnyxResponse object that has some basic information about the response that conveyed the error.
12 13 14 |
# File 'lib/telnyx/errors.rb', line 12 def response @response end |
Instance Method Details
#error_count ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/telnyx/errors.rb', line 55 def error_count case @errors when Array @errors.count else 1 end end |
#message ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/telnyx/errors.rb', line 46 def case @errors when Array "#{@errors[0]['title']} " else @errors end end |
#other_errors_message ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/telnyx/errors.rb', line 37 def count = error_count if count > 2 "plus #{count} other errors. " elsif count == 2 "plus 1 other error. " end end |
#stringify_errors(errors) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/telnyx/errors.rb', line 72 def stringify_errors(errors) if errors.is_a? Array errors.map { |h| stringify_hash(h) } elsif errors.is_a? Hash stringify_hash errors else errors end end |
#stringify_hash(h) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/telnyx/errors.rb', line 64 def stringify_hash(h) str_hash = {} h.each_key do |k| str_hash[k.to_s] = h[k] end str_hash end |
#to_s ⇒ Object
30 31 32 33 34 35 |
# File 'lib/telnyx/errors.rb', line 30 def to_s status_string = @http_status.nil? ? "" : "(Status #{@http_status}) " id_string = @request_id.nil? ? "" : "(Request #{@request_id}) " instruction = "Full details: #{@errors}" "#{status_string}#{id_string}#{}#{}#{instruction}" end |