Exception: Ridley::Errors::HTTPError
- Inherits:
-
RidleyError
- Object
- StandardError
- RidleyError
- Ridley::Errors::HTTPError
- Defined in:
- lib/ridley/errors.rb
Direct Known Subclasses
HTTPBadGateway, HTTPBadRequest, HTTPConflict, HTTPForbidden, HTTPGatewayTimeout, HTTPInternalServerError, HTTPMethodNotAllowed, HTTPNotFound, HTTPNotImplemented, HTTPRequestTimeout, HTTPServiceUnavailable, HTTPUnauthorized, HTTPUnknownStatus
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#message ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute message.
Class Method Summary collapse
- .error_map ⇒ Object
- .fabricate(env) ⇒ Object
- .lookup_error(status) ⇒ Object
- .register_error(status) ⇒ Object
Instance Method Summary collapse
-
#initialize(env) ⇒ HTTPError
constructor
A new instance of HTTPError.
Constructor Details
#initialize(env) ⇒ HTTPError
Returns a new instance of HTTPError.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ridley/errors.rb', line 55 def initialize(env) @env = env @errors = env[:body].is_a?(Hash) ? Array(env[:body][:error]) : [] if errors.empty? @message = env[:body] || "no content body" else @message = "errors: " @message << errors.collect { |e| "'#{e}'" }.join(', ') end end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
49 50 51 |
# File 'lib/ridley/errors.rb', line 49 def env @env end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
50 51 52 |
# File 'lib/ridley/errors.rb', line 50 def errors @errors end |
#message ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute message.
52 53 54 |
# File 'lib/ridley/errors.rb', line 52 def @message end |
Class Method Details
.error_map ⇒ Object
44 45 46 |
# File 'lib/ridley/errors.rb', line 44 def error_map @@error_map ||= Hash.new end |
.fabricate(env) ⇒ Object
29 30 31 32 |
# File 'lib/ridley/errors.rb', line 29 def fabricate(env) klass = lookup_error(env[:status].to_i) klass.new(env) end |
.lookup_error(status) ⇒ Object
38 39 40 41 42 |
# File 'lib/ridley/errors.rb', line 38 def lookup_error(status) error_map.fetch(status.to_i) rescue KeyError HTTPUnknownStatus end |
.register_error(status) ⇒ Object
34 35 36 |
# File 'lib/ridley/errors.rb', line 34 def register_error(status) error_map[status.to_i] = self end |