Skip to content

Commit

Permalink
Update tests for HTTP 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Oct 11, 2023
1 parent 9b6023d commit c28fb52
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions test/tests.jl
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
function handle_http_error(e)
# New HTTP error code in 0.9.13+
if isa(e, HTTP.TimeoutRequest.ReadTimeoutError)
return -Base.Libc.ECONNRESET
end

if !isa(e, HTTP.IOExtras.IOError)
# If this is not an HTTP error at all, rethrow it immediately
if !isa(e, HTTP.Exceptions.HTTPError)
rethrow(e)
end

# Peel it to get the inner exception
e = e.e

# If it just can't connect, deal with it silently, otherwise rethrow
if isa(e, Base.IOError)
if e.code in (-Base.Libc.ECONNREFUSED, -Base.Libc.EPIPE, -Base.Libc.ECONNRESET)
return e.code
end
end
# I don't know how this occurs, but it does sometimes. Probably an HTTP bug.
# Seems to happen together with the readtimeout kwarg to HTTP.get. In
# particular, this also results in the "file size mismatch" error log
# message from serve_file(...).
if isa(e, Base.EOFError)
# If it's a timeout error, return `-ECONNRESET`
if isa(e, HTTP.TimeoutError)
return -Base.Libc.ECONNRESET
end

# If it's a connection error, return the specific code, usually `ECONNREFUSED` or `EPIPE`
if isa(e, HTTP.ConnectError)
return e.error.ex.code
end

# If it's none of the "whitelisted" errors, rethrow it.
rethrow(e)
end
Expand Down

0 comments on commit c28fb52

Please sign in to comment.