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

Improve Amazon error detection #4402

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openlibrary/core/vendors.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ def _get_amazon_metadata(id_, id_type='isbn', resources=None):

try:
r = requests.get('http://%s/isbn/%s' % (affiliate_server_url, id_))
r.raise_for_status()
return r.json().get('hit') or None
except requests.exceptions.ConnectionError:
logger.exception("Affiliate Server unreachable")
return None
except requests.exceptions.HTTPError:
logger.exception("Affiliate Server: id {} not found".format(id_))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message will be misleading for error response codes other than 404. It may be better to include the response code and the reason in the log message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.python.org/3/library/logging.html#logging.exception writes a full stack trace (https://docs.python.org/3/library/traceback.html) to the log so that all exception details are available.

return None


def split_amazon_title(full_title):
Expand Down