Exception: Ridley::Errors::HTTPError
- Inherits:
-
RidleyError
- Object
- StandardError
- RidleyError
- Ridley::Errors::HTTPError
- Defined in:
- lib/ridley/errors.rb
Direct Known Subclasses
HTTP3XXError, HTTP4XXError, HTTP5XXError, HTTPUnknownMethod, 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
permalink #initialize(env) ⇒ HTTPError
Returns a new instance of HTTPError.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ridley/errors.rb', line 118 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
permalink #env ⇒ Object (readonly)
Returns the value of attribute env.
112 113 114 |
# File 'lib/ridley/errors.rb', line 112 def env @env end |
permalink #errors ⇒ Object (readonly)
Returns the value of attribute errors.
113 114 115 |
# File 'lib/ridley/errors.rb', line 113 def errors @errors end |
permalink #message ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute message.
115 116 117 |
# File 'lib/ridley/errors.rb', line 115 def @message end |
Class Method Details
permalink .error_map ⇒ Object
[View source]
107 108 109 |
# File 'lib/ridley/errors.rb', line 107 def error_map @@error_map ||= Hash.new end |
permalink .fabricate(env) ⇒ Object
[View source]
92 93 94 95 |
# File 'lib/ridley/errors.rb', line 92 def fabricate(env) klass = lookup_error(env[:status].to_i) klass.new(env) end |
permalink .lookup_error(status) ⇒ Object
[View source]
101 102 103 104 105 |
# File 'lib/ridley/errors.rb', line 101 def lookup_error(status) error_map.fetch(status.to_i) rescue KeyError HTTPUnknownStatus end |
permalink .register_error(status) ⇒ Object
[View source]
97 98 99 |
# File 'lib/ridley/errors.rb', line 97 def register_error(status) error_map[status.to_i] = self end |