Exception: VerifyAnyEmail::Error
- Inherits:
-
StandardError
- Object
- StandardError
- VerifyAnyEmail::Error
- Defined in:
- lib/verifyanyemail/error.rb
Overview
Raised for any non-success API response, transport failure, or invalid usage.
When the API returns a JSON error body of the shape
{ "error": "<code>", "message": "<human message>" }, the #code and
#message readers expose those fields and #status carries the HTTP
status code. Notable statuses:
401 - Missing or invalid API key
402 - Insufficient credits
413 - Batch too large for your plan
429 - Rate limited / concurrent batch limit reached
Instance Attribute Summary collapse
-
#body ⇒ Hash?
readonly
The raw parsed JSON body of the error response, if any.
-
#code ⇒ String?
readonly
Machine-readable error code from the JSON body (
error). -
#status ⇒ Integer?
readonly
HTTP status code, when the error came from a response.
Class Method Summary collapse
-
.from_response(status, parsed, raw_body = nil) ⇒ VerifyAnyEmail::Error
Build an Error from an HTTP status and a parsed (or unparsed) body.
Instance Method Summary collapse
-
#initialize(message = nil, status: nil, code: nil, body: nil) ⇒ Error
constructor
A new instance of Error.
-
#payment_required? ⇒ Boolean
True when the account has insufficient credits (HTTP 402).
-
#rate_limited? ⇒ Boolean
True when the request was rate limited (HTTP 429).
-
#unauthorized? ⇒ Boolean
True when the failure is due to a missing or invalid API key (HTTP 401).
Constructor Details
#initialize(message = nil, status: nil, code: nil, body: nil) ⇒ Error
Returns a new instance of Error.
29 30 31 32 33 34 |
# File 'lib/verifyanyemail/error.rb', line 29 def initialize( = nil, status: nil, code: nil, body: nil) @status = status @code = code @body = body super( || code || "VerifyAnyEmail::Error") end |
Instance Attribute Details
#body ⇒ Hash? (readonly)
Returns The raw parsed JSON body of the error response, if any.
23 24 25 |
# File 'lib/verifyanyemail/error.rb', line 23 def body @body end |
#code ⇒ String? (readonly)
Returns Machine-readable error code from the JSON body (error).
20 21 22 |
# File 'lib/verifyanyemail/error.rb', line 20 def code @code end |
#status ⇒ Integer? (readonly)
Returns HTTP status code, when the error came from a response.
17 18 19 |
# File 'lib/verifyanyemail/error.rb', line 17 def status @status end |
Class Method Details
.from_response(status, parsed, raw_body = nil) ⇒ VerifyAnyEmail::Error
Build an VerifyAnyEmail::Error from an HTTP status and a parsed (or unparsed) body.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/verifyanyemail/error.rb', line 60 def self.from_response(status, parsed, raw_body = nil) code = nil = nil if parsed.is_a?(Hash) code = parsed["error"] || parsed[:error] = parsed["message"] || parsed[:message] end ||= raw_body = "HTTP #{status}" if .nil? || .to_s.empty? new(, status: status, code: code, body: (parsed.is_a?(Hash) ? parsed : nil)) end |
Instance Method Details
#payment_required? ⇒ Boolean
True when the account has insufficient credits (HTTP 402).
44 45 46 |
# File 'lib/verifyanyemail/error.rb', line 44 def payment_required? status == 402 end |
#rate_limited? ⇒ Boolean
True when the request was rate limited (HTTP 429).
50 51 52 |
# File 'lib/verifyanyemail/error.rb', line 50 def rate_limited? status == 429 end |
#unauthorized? ⇒ Boolean
True when the failure is due to a missing or invalid API key (HTTP 401).
38 39 40 |
# File 'lib/verifyanyemail/error.rb', line 38 def status == 401 end |