Skip to content

Commit b950a3b

Browse files
CM-61550: Handle HTTP 408 with a user-friendly slow connection message
Adds HttpRequestTimeoutError as a distinct subclass of RequestHttpError for 408 responses, so users see a specific message about slow connections instead of the generic "unable to complete scan" error. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 49ec713 commit b950a3b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cycode/cli/exceptions/custom_exceptions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ def __str__(self) -> str:
5555
return f'HTTP unauthorized error occurred during the request. Message: {self.error_message}'
5656

5757

58+
class HttpRequestTimeoutError(RequestHttpError):
59+
def __init__(self, error_message: str, response: Response) -> None:
60+
super().__init__(408, error_message, response)
61+
62+
def __str__(self) -> str:
63+
return f'HTTP request timeout error occurred during the request. Message: {self.error_message}'
64+
65+
5866
class ZipTooLargeError(CycodeError):
5967
def __init__(self, size_limit: int) -> None:
6068
self.size_limit = size_limit
@@ -93,6 +101,12 @@ def __str__(self) -> str:
93101
code='timeout_error',
94102
message='The request timed out. Please try again by executing the `cycode scan` command',
95103
),
104+
HttpRequestTimeoutError: CliError(
105+
soft_fail=True,
106+
code='request_timeout_error',
107+
message='The scan upload timed out. This may be due to a slow connection. '
108+
'Please try again by executing the `cycode scan` command',
109+
),
96110
HttpUnauthorizedError: CliError(
97111
soft_fail=True,
98112
code='auth_error',

cycode/cyclient/cycode_client_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from tenacity import retry, retry_if_exception, stop_after_attempt, wait_random_exponential
1010

1111
from cycode.cli.exceptions.custom_exceptions import (
12+
HttpRequestTimeoutError,
1213
HttpUnauthorizedError,
1314
RequestConnectionError,
1415
RequestError,
@@ -185,4 +186,7 @@ def _get_http_exception(e: exceptions.HTTPError) -> RequestError:
185186
if e.response.status_code == 401:
186187
return HttpUnauthorizedError(e.response.text, e.response)
187188

189+
if e.response.status_code == 408:
190+
return HttpRequestTimeoutError(e.response.text, e.response)
191+
188192
return RequestHttpError(e.response.status_code, e.response.text, e.response)

0 commit comments

Comments
 (0)