Class: HTTPX::ErrorResponse
- Inherits:
-
Object
- Object
- HTTPX::ErrorResponse
- Extended by:
- Forwardable
- Includes:
- ErrorResponsePatternMatchExtensions, Loggable
- Defined in:
- lib/httpx/response.rb
Overview
Wraps an error which has happened while processing an HTTP Request. It has partial public API parity with HTTPX::Response, so users should rely on it to infer whether the returned response is one or the other.
response = HTTPX.get("https://some-domain/path") #=> response is HTTPX::Response or HTTPX::ErrorResponse
response.raise_for_status #=> raises if it wraps an error
Constant Summary
Constants included from Loggable
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
the wrapped exception.
-
#request ⇒ Object
readonly
the corresponding HTTPX::Request instance.
-
#response ⇒ Object
readonly
the HTTPX::Response instance, when there is one (i.e. error happens fetching the response).
Instance Method Summary collapse
-
#close ⇒ Object
closes the error resources.
-
#finished? ⇒ Boolean
always true for error responses.
-
#initialize(request, error, options) ⇒ ErrorResponse
constructor
A new instance of ErrorResponse.
-
#raise_for_status ⇒ Object
raises the wrapped exception.
-
#to_s ⇒ Object
returns the exception full message.
Methods included from ErrorResponsePatternMatchExtensions
#deconstruct, #deconstruct_keys
Methods included from Loggable
Constructor Details
#initialize(request, error, options) ⇒ ErrorResponse
Returns a new instance of ErrorResponse.
236 237 238 239 240 241 242 |
# File 'lib/httpx/response.rb', line 236 def initialize(request, error, ) @request = request @response = request.response if request.response.is_a?(Response) @error = error @options = Options.new() log_exception(@error) end |
Instance Attribute Details
#error ⇒ Object (readonly)
the wrapped exception.
228 229 230 |
# File 'lib/httpx/response.rb', line 228 def error @error end |
#request ⇒ Object (readonly)
the corresponding HTTPX::Request instance.
222 223 224 |
# File 'lib/httpx/response.rb', line 222 def request @request end |
#response ⇒ Object (readonly)
the HTTPX::Response instance, when there is one (i.e. error happens fetching the response).
225 226 227 |
# File 'lib/httpx/response.rb', line 225 def response @response end |
Instance Method Details
#close ⇒ Object
closes the error resources.
250 251 252 |
# File 'lib/httpx/response.rb', line 250 def close @response.close if @response && @response.respond_to?(:close) end |
#finished? ⇒ Boolean
always true for error responses.
255 256 257 |
# File 'lib/httpx/response.rb', line 255 def finished? true end |
#raise_for_status ⇒ Object
raises the wrapped exception.
260 261 262 |
# File 'lib/httpx/response.rb', line 260 def raise_for_status raise @error end |
#to_s ⇒ Object
returns the exception full message.
245 246 247 |
# File 'lib/httpx/response.rb', line 245 def to_s @error.(highlight: false) end |