Exception: RelayGrid::APIError
- Defined in:
- lib/relaygrid/errors.rb
Overview
The server answered, but not with success.
Direct Known Subclasses
AuthenticationError, LimitExceededError, NotFoundError, ServerError, ValidationError
Instance Attribute Summary collapse
-
#body ⇒ Hash, ...
readonly
Parsed response body.
-
#status ⇒ Integer?
readonly
HTTP status.
Class Method Summary collapse
-
.from_response(status, body) ⇒ Object
Maps an HTTP response onto the right subclass.
Instance Method Summary collapse
-
#error_message ⇒ Object
The server's own
errorstring when it sent one. -
#initialize(message = nil, status: nil, body: nil) ⇒ APIError
constructor
A new instance of APIError.
Constructor Details
#initialize(message = nil, status: nil, body: nil) ⇒ APIError
Returns a new instance of APIError.
24 25 26 27 28 |
# File 'lib/relaygrid/errors.rb', line 24 def initialize( = nil, status: nil, body: nil) @status = status @body = body super( || ) end |
Instance Attribute Details
#body ⇒ Hash, ... (readonly)
Returns parsed response body.
22 23 24 |
# File 'lib/relaygrid/errors.rb', line 22 def body @body end |
#status ⇒ Integer? (readonly)
Returns HTTP status.
20 21 22 |
# File 'lib/relaygrid/errors.rb', line 20 def status @status end |
Class Method Details
.from_response(status, body) ⇒ Object
Maps an HTTP response onto the right subclass. 404s are discriminated further by the server's message so callers can tell "no such template" from "no such user" without string-matching themselves.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/relaygrid/errors.rb', line 38 def self.from_response(status, body) klass = case status when 401, 403 then AuthenticationError when 402 then LimitExceededError when 404 then not_found_class(body) when 422 then ValidationError when 400..499 then APIError when 500..599 then ServerError else APIError end klass.new(status: status, body: body) end |
Instance Method Details
#error_message ⇒ Object
The server's own error string when it sent one.
31 32 33 |
# File 'lib/relaygrid/errors.rb', line 31 def body["error"] if body.is_a?(Hash) end |