Exception: Faraday::HttpError
- Inherits:
-
StandardError
- Object
- StandardError
- Faraday::HttpError
show all
- Defined in:
- lib/faraday/http_error.rb,
lib/faraday/http_error/version.rb,
lib/faraday/http_error/raise_error.rb
Defined Under Namespace
Classes: BadRequest, ClientError, Forbidden, InternalServerError, NotFound, RaiseError, ServerError, ServiceUnavailable, UnprocessableEntity
Constant Summary
collapse
- VERSION =
'0.0.2'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(body = nil) ⇒ HttpError
8
9
10
11
12
13
14
|
# File 'lib/faraday/http_error.rb', line 8
def initialize(body = nil)
@body = body
message = "#{body}\n#{self.class.name} - " \
"version #{Faraday::HttpError::VERSION}"
super(message)
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6
7
8
|
# File 'lib/faraday/http_error.rb', line 6
def body
@body
end
|
Class Method Details
.class_error_for_status(http_status) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/faraday/http_error.rb', line 26
def self.class_error_for_status(http_status)
case http_status
when 400..499 then client_errors(http_status)
when 500..599 then server_errors(http_status)
end
end
|
.client_errors(http_status) ⇒ Object
.from_response(response) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/faraday/http_error.rb', line 16
def self.from_response(response)
status = response[:status].to_i
body = response[:body]
if (klass = class_error_for_status(status))
klass.new(body)
end
end
|
.server_errors(http_status) ⇒ Object