1
1
module ConnectionRequest
2
2
3
- using URIs, Sockets, Base64, LoggingExtras, ConcurrentUtilities
3
+ using URIs, Sockets, Base64, LoggingExtras, ConcurrentUtilities, ExceptionUnwrapping
4
4
using MbedTLS: SSLContext, SSLConfig
5
5
using OpenSSL: SSLStream
6
6
using .. Messages, .. IOExtras, .. Connections, .. Streams, .. Exceptions
@@ -79,7 +79,7 @@ function connectionlayer(handler)
79
79
io = newconnection (IOType, url. host, url. port; readtimeout= readtimeout, kw... )
80
80
catch e
81
81
if logerrors
82
- err = current_exceptions_to_string (CapturedException (e, catch_backtrace ()) )
82
+ err = current_exceptions_to_string ()
83
83
@error err type= Symbol (" HTTP.ConnectError" ) method= req. method url= req. url context= req. context logtag= logtag
84
84
end
85
85
req. context[:connect_errors ] = get (req. context, :connect_errors , 0 ) + 1
@@ -118,18 +118,13 @@ function connectionlayer(handler)
118
118
stream = Stream (req. response, io)
119
119
return handler (stream; readtimeout= readtimeout, logerrors= logerrors, logtag= logtag, kw... )
120
120
catch e
121
- while true
122
- if e isa CompositeException
123
- e = e. exceptions[1 ]
124
- elseif e isa TaskFailedException
125
- e = e. task. result
126
- else
127
- break
128
- end
129
- end
130
- root_err = e isa CapturedException ? e. ex : e
121
+ root_err = ExceptionUnwrapping. unwrap_exception_to_root (e)
131
122
# don't log if it's an HTTPError since we should have already logged it
132
- if logerrors && ! (root_err isa HTTPError)
123
+ if logerrors && err isa StatusError
124
+ err = current_exceptions_to_string ()
125
+ @error err type= Symbol (" HTTP.StatusError" ) method= req. method url= req. url context= req. context logtag= logtag
126
+ end
127
+ if logerrors && ! ExceptionUnwrapping. has_wrapped_exception (e, HTTPError)
133
128
err = current_exceptions_to_string (e)
134
129
@error err type= Symbol (" HTTP.ConnectionRequest" ) method= req. method url= req. url context= req. context logtag= logtag
135
130
end
@@ -141,7 +136,7 @@ function connectionlayer(handler)
141
136
req. context[:nothingwritten ] = true
142
137
end
143
138
root_err isa HTTPError || throw (RequestError (req, e))
144
- rethrow (e )
139
+ throw (root_err )
145
140
finally
146
141
releaseconnection (io, shouldreuse; kw... )
147
142
if ! shouldreuse
0 commit comments