From deba6212ea1ad08a7da387e20a41a9edc0ba499e Mon Sep 17 00:00:00 2001 From: snekek Date: Fri, 10 Jan 2020 13:19:12 -0800 Subject: [PATCH] added ege case incase ask the caterpillar is down --- pysychonaut/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pysychonaut/__init__.py b/pysychonaut/__init__.py index 77e2c8b..f1c159e 100644 --- a/pysychonaut/__init__.py +++ b/pysychonaut/__init__.py @@ -470,6 +470,8 @@ class AskTheCaterpillar: @staticmethod def ask_the_caterpillar(query): data = requests.post('https://www.askthecaterpillar.com/query', {"query": query}) - data = json.loads(data.text) - return data["data"]["messages"][0]["content"] - + if data.status_code == 200: + data = json.loads(data.text) + return data["data"]["messages"][0]["content"] + else: + return f"Error {r.status_code}: {r.reason}"