FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add status_code property on http error handling by wmarquardt · Pull Request #1185 · googleapis/google-api-python-client · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion docs/start.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Creating a request does not actually call the API. To execute the request and ge
try:
response = request.execute()
except HttpError as e:
print('Error response status code : {0}, reason : {1}'.format(e.resp.status, e.error_details))
print('Error response status code : {0}, reason : {1}'.format(e.status_code, e.error_details))
```

Alternatively, you can combine previous steps on a single line:
Expand Down
6 changes: 6 additions & 0 deletions googleapiclient/errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def __init__(self, resp, content, uri=None):
self.content = content
self.uri = uri
self.error_details = ""
self._get_reason()

@property
def status_code(self):
Comment thread
parthea marked this conversation as resolved.
"""Return the HTTP status code from the response content."""
return self.resp.status

def _get_reason(self):
"""Calculate the reason for the error from the response content."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def test_json_body(self):
reason="Failed",
)
error = HttpError(resp, content, uri="http://example.org")
self.assertEqual(error.error_details, "error details")
self.assertEqual(error.status_code, 400)
self.assertEqual(
str(error),
'<HttpError 400 when requesting http://example.org returned "country is required". Details: "error details">',
Expand Down

Back | FazBrowse Home | New Git URL