Add error checking

This commit is contained in:
juan 2022-05-14 12:11:36 +08:00
parent 81d8f1f892
commit 135f8d0b65

View File

@ -13,9 +13,12 @@ def getRecentDiscussion():
recent = {"title": "N/A", "link": "#"} recent = {"title": "N/A", "link": "#"}
obj = python_requests.get("https://talk.zhdo.space/api/recent/posts/week") obj = python_requests.get("https://talk.zhdo.space/api/recent/posts/week")
if obj.status_code == 200: if obj.status_code == 200:
recent["title"] = str(obj.json()[0]["topic"]["title"]) if not obj.json():
recent["link"] = discussionPrefix + str(obj.json()[0]["topic"]["slug"]) return recent
return recent else:
recent["title"] = str(obj.json()[0]["topic"]["title"])
recent["link"] = discussionPrefix + str(obj.json()[0]["topic"]["slug"])
return recent
else: else:
return "error" return "error"