Exception: Nahook::APIError
- Defined in:
- lib/nahook/errors.rb
Overview
Raised when the Nahook API returns an error response (4xx/5xx).
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
Machine-readable error code from the API.
-
#retry_after ⇒ Integer?
readonly
Seconds the client should wait before retrying.
-
#status ⇒ Integer
readonly
HTTP status code.
Instance Method Summary collapse
-
#auth_error? ⇒ Boolean
Whether this is an authentication or authorization error.
-
#initialize(status, code, message, retry_after = nil) ⇒ APIError
constructor
A new instance of APIError.
-
#not_found? ⇒ Boolean
Whether the requested resource was not found.
-
#rate_limited? ⇒ Boolean
Whether the request was rate limited.
-
#retryable? ⇒ Boolean
Whether this error is safe to retry (5xx or 429).
-
#validation_error? ⇒ Boolean
Whether the request failed validation.
Constructor Details
#initialize(status, code, message, retry_after = nil) ⇒ APIError
Returns a new instance of APIError.
31 32 33 34 35 36 |
# File 'lib/nahook/errors.rb', line 31 def initialize(status, code, , retry_after = nil) @status = status @code = code @retry_after = retry_after super() end |
Instance Attribute Details
#code ⇒ String (readonly)
Returns machine-readable error code from the API.
22 23 24 |
# File 'lib/nahook/errors.rb', line 22 def code @code end |
#retry_after ⇒ Integer? (readonly)
Returns seconds the client should wait before retrying.
25 26 27 |
# File 'lib/nahook/errors.rb', line 25 def retry_after @retry_after end |
#status ⇒ Integer (readonly)
Returns HTTP status code.
19 20 21 |
# File 'lib/nahook/errors.rb', line 19 def status @status end |
Instance Method Details
#auth_error? ⇒ Boolean
Whether this is an authentication or authorization error.
48 49 50 |
# File 'lib/nahook/errors.rb', line 48 def auth_error? status == 401 || (status == 403 && code == "token_disabled") end |
#not_found? ⇒ Boolean
Whether the requested resource was not found.
55 56 57 |
# File 'lib/nahook/errors.rb', line 55 def not_found? status == 404 end |
#rate_limited? ⇒ Boolean
Whether the request was rate limited.
62 63 64 |
# File 'lib/nahook/errors.rb', line 62 def rate_limited? status == 429 end |
#retryable? ⇒ Boolean
Whether this error is safe to retry (5xx or 429).
41 42 43 |
# File 'lib/nahook/errors.rb', line 41 def retryable? status >= 500 || status == 429 end |
#validation_error? ⇒ Boolean
Whether the request failed validation.
69 70 71 |
# File 'lib/nahook/errors.rb', line 69 def validation_error? status == 400 end |