Expose HttpError.reason when available
See original GitHub issueIs there a better way to get the error reason
than parsing HttpError.content
from json string to object?
This is what I’m currently doing:
try:
req = compute.zones().list(project=project_id, maxResults=max_results)
res = req.execute()
return res['items']
except HttpError as e:
reason = json.loads(e.content)['error']['errors'][0]['reason']
if reason == 'accessNotConfigured':
<do the thing>
Ideally I’d like to avoid the call to json.loads()
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How do I return HTTP error code without default template in ...
http.responses[status_code] returns the error code text like "page not found" based on the status code.
Read more >What Does HTTP Error 503 (Service Unavailable) Mean ...
A 503 Service Unavailable Error is an HTTP response status code that indicates your web server operates properly, but it can't handle a ......
Read more >How to pass custom reason to 'write_error' through 'raise ...
I want to use 'raise tornado.web.HTTPError(400, reason='invalid request')' to pass a custom reason to the error response, and I hope to do this...
Read more >HTTP response status codes - MDN Web Docs - Mozilla
This code indicates that the server has received and is processing the request, but no response is available yet.
Read more >HTTP Errors <httpErrors> - Microsoft Learn
You can use the <remove> element to remove a specific error message from the collection of error messages your site or application inherits...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I spoke to some other folks today, and I don’t think there’s a error response structure we can count on across all the APIs Google publishes.
If you need a particular field in an error response, parsing it from the JSON is the best option.
Hi,
Thanks for the additional context.
I’m not sure how consistent APIs are about defining errors. The YouTube Data API and Drive API seem to have a similar structure.
The Analytics API is different - the
status
seems to be the equivalent ofreason
.