Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove repeated calls to self._get_reason #1513

Merged
merged 1 commit into from Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions googleapiclient/errors.py
Expand Up @@ -43,7 +43,7 @@ def __init__(self, resp, content, uri=None):
self.content = content
self.uri = uri
self.error_details = ""
self._get_reason()
self.reason = self._get_reason()

@property
def status_code(self):
Expand Down Expand Up @@ -75,25 +75,24 @@ def _get_reason(self):
pass
if reason is None:
reason = ""
return reason
return reason.strip()

def __repr__(self):
reason = self._get_reason()
if self.error_details:
return '<HttpError %s when requesting %s returned "%s". Details: "%s">' % (
self.resp.status,
self.uri,
reason.strip(),
self.reason,
self.error_details,
)
elif self.uri:
return '<HttpError %s when requesting %s returned "%s">' % (
self.resp.status,
self.uri,
self._get_reason().strip(),
self.reason,
)
else:
return '<HttpError %s "%s">' % (self.resp.status, self._get_reason())
return '<HttpError %s "%s">' % (self.resp.status, self.reason)

__str__ = __repr__

Expand Down