Exception: TheCity::Error
- Inherits:
-
StandardError
- Object
- StandardError
- TheCity::Error
- Defined in:
- lib/the_city/error.rb,
lib/the_city/error/forbidden.rb,
lib/the_city/error/not_found.rb,
lib/the_city/error/bad_gateway.rb,
lib/the_city/error/bad_request.rb,
lib/the_city/error/unauthorized.rb,
lib/the_city/error/argument_arror.rb,
lib/the_city/error/not_acceptable.rb,
lib/the_city/error/gateway_timeout.rb,
lib/the_city/error/too_many_requests.rb,
lib/the_city/error/configuration_error.rb,
lib/the_city/error/service_unavailable.rb,
lib/the_city/error/unprocessable_entity.rb,
lib/the_city/error/internal_server_error.rb
Overview
Custom error class for rescuing from all The City API errors
Direct Known Subclasses
BadGateway, BadRequest, Forbidden, GatewayTimeout, InternalServerError, NotAcceptable, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity
Defined Under Namespace
Classes: ArgumentError, BadGateway, BadRequest, ConfigurationError, Forbidden, GatewayTimeout, InternalServerError, NotAcceptable, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity
Constant Summary collapse
- EnhanceYourCalm =
TooManyRequests- RateLimited =
TooManyRequests
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#rate_limit ⇒ Object
readonly
Returns the value of attribute rate_limit.
-
#wrapped_exception ⇒ Object
readonly
Returns the value of attribute wrapped_exception.
Class Method Summary collapse
- .descendants ⇒ Array
- .errors ⇒ Hash
-
.from_response(response = {}) ⇒ TheCity::Error
Create a new error from an HTTP response.
- .inherited(descendant) ⇒ Array
Instance Method Summary collapse
-
#initialize(exception = $!, response_headers = {}, code = nil) ⇒ TheCity::Error
constructor
Initializes a new Error object.
Constructor Details
#initialize(exception = $!, response_headers = {}, code = nil) ⇒ TheCity::Error
Initializes a new Error object
41 42 43 44 45 46 |
# File 'lib/the_city/error.rb', line 41 def initialize(exception=$!, response_headers={}, code=nil) @rate_limit = TheCity::RateLimit.new(response_headers) @wrapped_exception = exception @code = code exception.respond_to?(:message) ? super(exception.) : super(exception.to_s) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/the_city/error.rb', line 6 def code @code end |
#rate_limit ⇒ Object (readonly)
Returns the value of attribute rate_limit.
6 7 8 |
# File 'lib/the_city/error.rb', line 6 def rate_limit @rate_limit end |
#wrapped_exception ⇒ Object (readonly)
Returns the value of attribute wrapped_exception.
6 7 8 |
# File 'lib/the_city/error.rb', line 6 def wrapped_exception @wrapped_exception end |
Class Method Details
.descendants ⇒ Array
26 27 28 |
# File 'lib/the_city/error.rb', line 26 def self.descendants @descendants ||= [] end |
.errors ⇒ Hash
18 19 20 21 22 23 |
# File 'lib/the_city/error.rb', line 18 def self.errors @errors ||= descendants.inject({}) do |hash, klass| hash[klass::HTTP_STATUS_CODE] = klass hash end end |
.from_response(response = {}) ⇒ TheCity::Error
Create a new error from an HTTP response
12 13 14 15 |
# File 'lib/the_city/error.rb', line 12 def self.from_response(response={}) error, code = parse_error(response[:body]) new(error, response[:response_headers], code) end |
.inherited(descendant) ⇒ Array
31 32 33 |
# File 'lib/the_city/error.rb', line 31 def self.inherited(descendant) descendants << descendant end |