From 61a6a0239b0b7b98bd291198ae810cb3517d26c9 Mon Sep 17 00:00:00 2001 From: gitpushoriginmaster <32514250+gitpushoriginmaster@users.noreply.github.com> Date: Mon, 21 Jul 2025 11:04:53 +0000 Subject: [PATCH] Improve error message formatting in Response class to not give a link for unofficial codes. --- httpx/_models.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/httpx/_models.py b/httpx/_models.py index 2cc86321a4..bbe6a345e7 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -805,17 +805,11 @@ def raise_for_status(self) -> Response: if self.is_success: return self + message = "{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'" if self.has_redirect_location: - message = ( - "{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'\n" - "Redirect location: '{0.headers[location]}'\n" - "For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}" - ) - else: - message = ( - "{error_type} '{0.status_code} {0.reason_phrase}' for url '{0.url}'\n" - "For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}" - ) + message += "\nRedirect location: '{0.headers[location]}'" + if self.reason_phrase: + message += "\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/{0.status_code}" status_class = self.status_code // 100 error_types = {