chore: Error Logging and exception hnadling on connection failure

This commit is contained in:
marination 2020-08-02 17:13:34 +05:30
parent c16ace6732
commit e3495116dd

View File

@ -26,6 +26,7 @@ def get_video_stats(docname, youtube_id, update=True):
api_key = frappe.db.get_single_value("Video Settings", "api_key")
api = Api(api_key=api_key)
try:
video = api.get_video_by_id(video_id=youtube_id)
video_stats = video.items[0].to_dict().get('statistics')
stats = {
@ -47,3 +48,6 @@ def get_video_stats(docname, youtube_id, update=True):
comment_count = %(comment_count)s
WHERE name = {0}""".format(frappe.db.escape(docname)), stats) #nosec
frappe.db.commit()
except:
message = "Please make sure you are connected to the Internet"
frappe.log_error(message + "\n\n" + frappe.get_traceback(), "Failed to Update YouTube Statistics for Video: {0}".format(docname))