Skip to content

Commit a1eb82b

Browse files
authored
Restore HTTP.Exceptions as a deprecating compat shim + migration note (#1315)
Re-add HTTP.Exceptions as a thin deprecated submodule forwarding HTTPError, StatusError, ConnectError and TimeoutError to the canonical top-level names via Base.@deprecate_binding (as the existing escape -> escapeuri), so downstream `catch ... isa HTTP.Exceptions.StatusError` keeps working with a deprecation warning. RequestError, @Try and current_exceptions_to_string are not reinstated; the migration guide documents them (RequestError has no drop-in -- the underlying exception propagates and isrecoverable classifies it). Closes #1314.
1 parent 11eb5f8 commit a1eb82b

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

docs/src/guides/migration-1x.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,55 @@ Use the timeout that matches your intent:
359359
Timeout failures are reported as `HTTP.HTTPTimeoutError`, an alias for
360360
`HTTP.TimeoutError`.
361361

362+
## Exceptions
363+
364+
In 1.x the client exception types lived in the `HTTP.Exceptions` submodule and were
365+
re-exported to the top level. 2.x keeps the types at the top level — `HTTP.StatusError`,
366+
`HTTP.ConnectError`, `HTTP.TimeoutError`, and their `HTTP.HTTPError` supertype — and
367+
`HTTP.Exceptions` is now a thin deprecated shim. Prefer the top-level names.
368+
369+
Before:
370+
371+
```julia
372+
catch e
373+
e isa HTTP.Exceptions.StatusError && @info "status" e.status
374+
end
375+
```
376+
377+
After:
378+
379+
```julia
380+
catch e
381+
e isa HTTP.StatusError && @info "status" e.status
382+
end
383+
```
384+
385+
`HTTP.Exceptions.StatusError`, `ConnectError`, `TimeoutError`, and `HTTPError` still
386+
resolve — forwarding to the top-level names, with a deprecation warning under
387+
`--depwarn=yes`. The 1.x `@try` macro and `current_exceptions_to_string` helper were
388+
internal and are removed with no replacement.
389+
390+
`HTTP.RequestError` is also gone. 1.x wrapped request-path failures in a `RequestError`
391+
(fields `.request`/`.error`); 2.x lets the underlying transport or protocol exception
392+
propagate directly, and exposes `HTTP.isrecoverable` to classify whether a failure is a
393+
transient one that is safe to retry.
394+
395+
Before:
396+
397+
```julia
398+
catch e
399+
e isa HTTP.Exceptions.RequestError && @warn "request failed" e.error
400+
end
401+
```
402+
403+
After:
404+
405+
```julia
406+
catch e
407+
HTTP.isrecoverable(e) || rethrow() # otherwise it is a transient transport failure
408+
end
409+
```
410+
362411
## TLS, Sockets, and Proxies
363412

364413
The old `sslconfig` and `socket_type_tls` extension points are retained for
@@ -641,6 +690,7 @@ Treat these as temporary migration aids. New code should use the documented
641690
- Prefer keyword constructors for `Request` and `Response`.
642691
- Replace `pool` usage with a long-lived `HTTP.Client`.
643692
- Replace `readtimeout` with the precise timeout keyword you need.
693+
- Replace `HTTP.Exceptions.StatusError` & friends with the top-level `HTTP.StatusError`; `HTTP.RequestError` is gone — catch the underlying exception or use `HTTP.isrecoverable`.
644694
- Replace `HTTP.download` with `Downloads.download` or an explicit
645695
`HTTP.request(...; response_stream = io)` file stream.
646696
- Move WebSocket code to `HTTP.WebSockets`.

src/HTTP.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ include("http_websockets.jl")
8787
))
8888
end
8989

90+
# Backward-compatibility shim for the 1.x `HTTP.Exceptions` submodule. In 1.x these
91+
# exception types were defined in `HTTP.Exceptions` and re-exported to the top level;
92+
# 2.x keeps them at the top level (`HTTP.StatusError` etc.) but dropped the submodule,
93+
# breaking downstream code that reached in via `HTTP.Exceptions.StatusError`. Re-add a
94+
# thin deprecated `Exceptions` module forwarding to the canonical names — see #1314.
95+
# (`@try`, `current_exceptions_to_string` and `RequestError` are not reinstated; see the
96+
# migration guide.)
97+
module Exceptions
98+
import ..HTTP
99+
Base.@deprecate_binding HTTPError HTTP.HTTPError false
100+
Base.@deprecate_binding StatusError HTTP.StatusError false
101+
Base.@deprecate_binding ConnectError HTTP.ConnectError false
102+
Base.@deprecate_binding TimeoutError HTTP.TimeoutError false
103+
end
104+
90105
if ccall(:jl_generating_output, Cint, ()) == 1
91106
include("precompile.jl")
92107
end

0 commit comments

Comments
 (0)