Exception: VoiceTel::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- VoiceTel::ApiError
- Defined in:
- lib/voicetel/api_error.rb
Overview
ApiError is raised on every non-2xx response (and on transport failures).
‘kind` is a Symbol classifying the failure so callers can pattern-match without checking HTTP status codes directly. The convenience predicates (`rate_limit?`, `not_found?`, etc.) are exposed for readability.
Constant Summary collapse
- KINDS =
%i[ bad_request authentication permission_denied not_found conflict rate_limit server unknown ].freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, kind: :unknown, status_code: nil, code: nil, body: nil) ⇒ ApiError
constructor
A new instance of ApiError.
Constructor Details
#initialize(message, kind: :unknown, status_code: nil, code: nil, body: nil) ⇒ ApiError
Returns a new instance of ApiError.
23 24 25 26 27 28 29 |
# File 'lib/voicetel/api_error.rb', line 23 def initialize(, kind: :unknown, status_code: nil, code: nil, body: nil) super() @kind = kind @status_code = status_code @code = code @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
21 22 23 |
# File 'lib/voicetel/api_error.rb', line 21 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
21 22 23 |
# File 'lib/voicetel/api_error.rb', line 21 def code @code end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
21 22 23 |
# File 'lib/voicetel/api_error.rb', line 21 def kind @kind end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
21 22 23 |
# File 'lib/voicetel/api_error.rb', line 21 def status_code @status_code end |
Class Method Details
.from_response(status, code, message, body) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/voicetel/api_error.rb', line 49 def self.from_response(status, code, , body) new( , kind: kind_from_status(status), status_code: status, code: code, body: body ) end |
.kind_from_status(status) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/voicetel/api_error.rb', line 36 def self.kind_from_status(status) case status when 400 then :bad_request when 401 then :authentication when 403 then :permission_denied when 404 then :not_found when 409 then :conflict when 429 then :rate_limit when 500..599 then :server else :unknown end end |