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
Loggable::COLORS, Loggable::USE_DEBUG_LOG
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
-
#<<(data) ⇒ Object
buffers lost chunks to error response.
-
#close ⇒ Object
closes the error resources.
- #finish! ⇒ Object
-
#finished? ⇒ Boolean
always true for error responses.
-
#initialize(request, error) ⇒ 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
#log, #log_exception, #log_redact, #log_redact_body, #log_redact_headers
Constructor Details
#initialize(request, error) ⇒ ErrorResponse
Returns a new instance of ErrorResponse.
279 280 281 282 283 284 285 |
# File 'lib/httpx/response.rb', line 279 def initialize(request, error) @request = request @response = request.response if request.response.is_a?(Response) @error = error = request. log_exception(@error) end |
Instance Attribute Details
#error ⇒ Object (readonly)
the wrapped exception.
271 272 273 |
# File 'lib/httpx/response.rb', line 271 def error @error end |
#request ⇒ Object (readonly)
the corresponding HTTPX::Request instance.
265 266 267 |
# File 'lib/httpx/response.rb', line 265 def request @request end |
#response ⇒ Object (readonly)
the HTTPX::Response instance, when there is one (i.e. error happens fetching the response).
268 269 270 |
# File 'lib/httpx/response.rb', line 268 def response @response end |
Instance Method Details
#<<(data) ⇒ Object
buffers lost chunks to error response
310 311 312 313 314 |
# File 'lib/httpx/response.rb', line 310 def <<(data) return unless @response @response << data end |
#close ⇒ Object
closes the error resources.
293 294 295 |
# File 'lib/httpx/response.rb', line 293 def close @response.close if @response end |
#finish! ⇒ Object
302 |
# File 'lib/httpx/response.rb', line 302 def finish!; end |
#finished? ⇒ Boolean
always true for error responses.
298 299 300 |
# File 'lib/httpx/response.rb', line 298 def finished? true end |
#raise_for_status ⇒ Object
raises the wrapped exception.
305 306 307 |
# File 'lib/httpx/response.rb', line 305 def raise_for_status raise @error end |
#to_s ⇒ Object
returns the exception full message.
288 289 290 |
# File 'lib/httpx/response.rb', line 288 def to_s @error.(highlight: false) end |