Skip to content

Commit 0c186a3

Browse files
handle client connection errors
Signed-off-by: Achille Roussel <[email protected]>
1 parent 2803551 commit 0c186a3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/dispatch/http.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
overload,
1717
)
1818

19-
from aiohttp import web
19+
from aiohttp import web, ClientConnectionError
2020
from http_message_signatures import InvalidSignature
2121
from typing_extensions import ParamSpec, TypeAlias
2222

@@ -30,7 +30,10 @@
3030
parse_verification_key,
3131
verify_request,
3232
)
33-
from dispatch.status import Status
33+
from dispatch.status import Status, register_error_type
34+
35+
# https://docs.aiohttp.org/en/stable/client_reference.html
36+
register_error_type(ClientConnectionError, Status.TCP_ERROR)
3437

3538
logger = logging.getLogger(__name__)
3639

src/dispatch/status.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import enum
2+
import ssl
23
from typing import Any, Callable, Dict, Type, Union
34

45
from dispatch.sdk.v1 import status_pb2 as status_pb
@@ -129,6 +130,8 @@ def status_for_error(error: BaseException) -> Status:
129130
# tend to be caused by invalid use of syscalls, which are
130131
# unlikely at higher abstraction levels.
131132
return Status.TEMPORARY_ERROR
133+
elif isinstance(error, ssl.SSLError) or isinstance(error, ssl.CertificateError):
134+
return Status.TLS_ERROR
132135
return Status.PERMANENT_ERROR
133136

134137

0 commit comments

Comments
 (0)