mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
error response must also reflect the request
This commit is contained in:
parent
08fd0452e9
commit
9a4b836ae7
@ -177,8 +177,8 @@ module HTTPX
|
||||
end
|
||||
|
||||
def send(request)
|
||||
if @error_response
|
||||
emit(:response, request, @error_response)
|
||||
if @error
|
||||
emit(:response, request, ErrorResponse.new(request, @error, @options))
|
||||
elsif @parser && !@write_buffer.full?
|
||||
request.headers["alt-used"] = @origin.authority if match_altsvcs?(request.uri)
|
||||
parser.send(request)
|
||||
@ -297,7 +297,7 @@ module HTTPX
|
||||
when MisdirectedRequestError
|
||||
emit(:uncoalesce, request.uri)
|
||||
else
|
||||
response = ErrorResponse.new(ex, @options)
|
||||
response = ErrorResponse.new(request, ex, @options)
|
||||
request.emit(:response, response)
|
||||
end
|
||||
end
|
||||
@ -306,7 +306,7 @@ module HTTPX
|
||||
def transition(nextstate)
|
||||
case nextstate
|
||||
when :idle
|
||||
@error_response = nil
|
||||
@error = nil
|
||||
@timeout_threshold = @options.timeout.connect_timeout
|
||||
@timeout = @timeout_threshold
|
||||
when :open
|
||||
@ -363,9 +363,9 @@ module HTTPX
|
||||
end
|
||||
|
||||
parser.handle_error(e) if @parser && parser.respond_to?(:handle_error)
|
||||
@error_response = ErrorResponse.new(e, @options)
|
||||
@error = e
|
||||
@pending.each do |request, _|
|
||||
request.emit(:response, @error_response)
|
||||
request.emit(:response, ErrorResponse.new(request, @error, @options))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ module HTTPX
|
||||
retry_request.uri.scheme == "http"
|
||||
error = InsecureRedirectError.new(retry_request.uri.to_s)
|
||||
error.set_backtrace(caller)
|
||||
return ErrorResponse.new(error, options)
|
||||
return ErrorResponse.new(request, error, options)
|
||||
end
|
||||
|
||||
connection = find_connection(retry_request, connections, options)
|
||||
|
@ -238,9 +238,10 @@ module HTTPX
|
||||
class ErrorResponse
|
||||
include Loggable
|
||||
|
||||
attr_reader :error
|
||||
attr_reader :request, :error
|
||||
|
||||
def initialize(error, options)
|
||||
def initialize(request, error, options)
|
||||
@request = request
|
||||
@error = error
|
||||
@options = Options.new(options)
|
||||
log_exception(@error)
|
||||
|
@ -6,18 +6,18 @@ class ErrorResponseTest < Minitest::Test
|
||||
include HTTPX
|
||||
|
||||
def test_response_status
|
||||
r1 = ErrorResponse.new(RuntimeError.new("wow"), {})
|
||||
r1 = ErrorResponse.new(Minitest::Mock.new, RuntimeError.new("wow"), {})
|
||||
assert r1.status == "wow"
|
||||
end
|
||||
|
||||
def test_response_raise_for_status
|
||||
some_error = Class.new(RuntimeError)
|
||||
r1 = ErrorResponse.new(some_error.new("wow"), {})
|
||||
r1 = ErrorResponse.new(Minitest::Mock.new, some_error.new("wow"), {})
|
||||
assert_raises(some_error) { r1.raise_for_status }
|
||||
end
|
||||
|
||||
def test_respond_method_missing_errors
|
||||
r1 = ErrorResponse.new(RuntimeError.new("wow"), {})
|
||||
r1 = ErrorResponse.new(Minitest::Mock.new, RuntimeError.new("wow"), {})
|
||||
ex1 = assert_raises(NoMethodError) { r1.headers }
|
||||
assert ex1.message =~ /undefined response method/
|
||||
ex2 = assert_raises(NoMethodError) { r1.bang }
|
||||
|
Loading…
x
Reference in New Issue
Block a user