Exception: Ja::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Ja::Error
- Defined in:
- lib/ja/error.rb
Constant Summary collapse
- ResponseError =
Base class for all errors
Class.new(Error)
- ClientError =
Base class for errors in the 4xx range
Class.new(ResponseError)
- ServerError =
Base class for errors in the 5xx range
Class.new(ResponseError)
Instance Attribute Summary collapse
-
#headline ⇒ Object
readonly
Returns the value of attribute headline.
-
#message ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute message.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(verb, uri, response) ⇒ Error
constructor
A new instance of Error.
- #status ⇒ Object
Constructor Details
#initialize(verb, uri, response) ⇒ Error
Returns a new instance of Error.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ja/error.rb', line 25 def initialize(verb, uri, response) @response = response @verb = verb @uri = uri @headline = "%{verb} %{url} responded with %{status}" % { status: response.status, verb: verb.to_s.upcase, url: uri.to_s, } @response_body = Ja.format_body(response.headers) { response.body.to_s } @message = @response_body ? "#{@headline}\n\n#{@response_body}" : @headline end |
Instance Attribute Details
#headline ⇒ Object (readonly)
Returns the value of attribute headline.
41 42 43 |
# File 'lib/ja/error.rb', line 41 def headline @headline end |
#message ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute message.
41 42 43 |
# File 'lib/ja/error.rb', line 41 def @message end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
23 24 25 |
# File 'lib/ja/error.rb', line 23 def response @response end |
#response_body ⇒ Object (readonly)
Returns the value of attribute response_body.
41 42 43 |
# File 'lib/ja/error.rb', line 41 def response_body @response_body end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
23 24 25 |
# File 'lib/ja/error.rb', line 23 def uri @uri end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
23 24 25 |
# File 'lib/ja/error.rb', line 23 def verb @verb end |
Class Method Details
.fetch_error_class(status) ⇒ Object
19 20 21 |
# File 'lib/ja/error.rb', line 19 def self.fetch_error_class(status) const_get(HTTP::Response::Status::REASONS.fetch(status, "ResponseError").gsub(/\W/, "")) end |
.to_exception(verb, uri, response) ⇒ Object
15 16 17 |
# File 'lib/ja/error.rb', line 15 def self.to_exception(verb, uri, response) Error.fetch_error_class(response.status).new(verb, uri, response) end |
Instance Method Details
#status ⇒ Object
45 46 47 |
# File 'lib/ja/error.rb', line 45 def status response.status end |