diff --git a/CHANGELOG.md b/CHANGELOG.md index f63110425..cc2ec746c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## Unreleased + +- Added httpcore.SSLError and redirect TLS handshake errors to it. (#960) + ## Version 1.0.6 (October 1st, 2024) - Relax `trio` dependency pinning. (#956) diff --git a/docs/exceptions.md b/docs/exceptions.md index 63ef3f28e..3d01dd057 100644 --- a/docs/exceptions.md +++ b/docs/exceptions.md @@ -9,6 +9,7 @@ The following exceptions may be raised when sending a request: * `httpcore.WriteTimeout` * `httpcore.NetworkError` * `httpcore.ConnectError` + * `httpcore.SSLError` * `httpcore.ReadError` * `httpcore.WriteError` * `httpcore.ProtocolError` diff --git a/httpcore/__init__.py b/httpcore/__init__.py index 330745a5d..5d2a1e601 100644 --- a/httpcore/__init__.py +++ b/httpcore/__init__.py @@ -29,6 +29,7 @@ ReadError, ReadTimeout, RemoteProtocolError, + SSLError, TimeoutException, UnsupportedProtocol, WriteError, @@ -128,6 +129,7 @@ def __init__(self, *args, **kwargs): # type: ignore "ConnectError", "ReadError", "WriteError", + "SSLError", ] __version__ = "1.0.6" diff --git a/httpcore/_backends/anyio.py b/httpcore/_backends/anyio.py index d469e0084..66d552e7f 100644 --- a/httpcore/_backends/anyio.py +++ b/httpcore/_backends/anyio.py @@ -8,6 +8,7 @@ ConnectTimeout, ReadError, ReadTimeout, + SSLError, WriteError, WriteTimeout, map_exceptions, @@ -64,7 +65,7 @@ async def start_tls( TimeoutError: ConnectTimeout, anyio.BrokenResourceError: ConnectError, anyio.EndOfStream: ConnectError, - ssl.SSLError: ConnectError, + ssl.SSLError: SSLError, } with map_exceptions(exc_map): try: diff --git a/httpcore/_exceptions.py b/httpcore/_exceptions.py index 81e7fc61d..e0f60fa5f 100644 --- a/httpcore/_exceptions.py +++ b/httpcore/_exceptions.py @@ -1,4 +1,5 @@ import contextlib +import ssl from typing import Iterator, Mapping, Type ExceptionMapping = Mapping[Type[Exception], Type[Exception]] @@ -79,3 +80,7 @@ class ReadError(NetworkError): class WriteError(NetworkError): pass + + +class SSLError(ssl.SSLError, ConnectError): + pass