File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 66
77_HTTP_METHOD_TOKEN_PATTERN = re .compile (r"^[!#$%&'*+\-.^_`|~0-9A-Z]+$" )
88_MAX_ERROR_MESSAGE_LENGTH = 2000
9+ _MAX_REQUEST_URL_DISPLAY_LENGTH = 1000
910
1011
1112def _normalize_request_method (method : Any ) -> str :
@@ -29,6 +30,8 @@ def _normalize_request_url(url: Any) -> str:
2930 ord (character ) < 32 or ord (character ) == 127 for character in normalized_url
3031 ):
3132 return "unknown URL"
33+ if len (normalized_url ) > _MAX_REQUEST_URL_DISPLAY_LENGTH :
34+ return f"{ normalized_url [:_MAX_REQUEST_URL_DISPLAY_LENGTH ]} ... (truncated)"
3235 return normalized_url
3336
3437
Original file line number Diff line number Diff line change @@ -204,6 +204,18 @@ def test_format_request_failure_message_normalizes_lowercase_fallback_method():
204204 assert message == "Request POST https://example.com/fallback failed"
205205
206206
207+ def test_format_request_failure_message_truncates_very_long_fallback_urls ():
208+ very_long_url = "https://example.com/" + ("a" * 1200 )
209+ message = format_request_failure_message (
210+ httpx .RequestError ("network down" ),
211+ fallback_method = "GET" ,
212+ fallback_url = very_long_url ,
213+ )
214+
215+ assert "Request GET https://example.com/" in message
216+ assert "... (truncated) failed" in message
217+
218+
207219def test_extract_error_message_handles_recursive_list_payloads ():
208220 recursive_payload = []
209221 recursive_payload .append (recursive_payload )
You can’t perform that action at this time.
0 commit comments