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 = {