Skip to content

Commit

Permalink
handle client connection errors
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Jun 17, 2024
1 parent 2803551 commit 0c186a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dispatch/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
overload,
)

from aiohttp import web
from aiohttp import web, ClientConnectionError
from http_message_signatures import InvalidSignature
from typing_extensions import ParamSpec, TypeAlias

Expand All @@ -30,7 +30,10 @@
parse_verification_key,
verify_request,
)
from dispatch.status import Status
from dispatch.status import Status, register_error_type

# https://docs.aiohttp.org/en/stable/client_reference.html
register_error_type(ClientConnectionError, Status.TCP_ERROR)

logger = logging.getLogger(__name__)

Expand Down
3 changes: 3 additions & 0 deletions src/dispatch/status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import ssl
from typing import Any, Callable, Dict, Type, Union

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


Expand Down

0 comments on commit 0c186a3

Please sign in to comment.