From 048fd1b4a7371e169e3a0d3d71775c0cc2a0eafe Mon Sep 17 00:00:00 2001 From: Ramon Wenger Date: Mon, 15 Feb 2021 15:22:40 +0100 Subject: [PATCH] Add more debugging info to taskbase call --- server/spellcheck/client.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/spellcheck/client.py b/server/spellcheck/client.py index f9a20a93..5d5de109 100644 --- a/server/spellcheck/client.py +++ b/server/spellcheck/client.py @@ -32,8 +32,14 @@ class TaskbaseClient: 'password': self.password } response = requests.post('{}/api/login'.format(self.base_url), json=payload) - data = response.json() - self.token = data['accessToken'] + if response.ok: + data = response.json() + self.token = data['accessToken'] + else: + if response.status_code == 401: + raise TaskbaseException('Unauthorized') + else: + raise TaskbaseException(f'Error Code: {response.status_code}') def register_assignment(self, assignment): if self.token is None: @@ -43,7 +49,7 @@ class TaskbaseClient: payload = {'type': 'SPELL_CHECK'} # we first need to register the assignment via API, so we get an ID response = requests.post('{}/api/task'.format(self.base_url), json=payload, headers=headers) - if response.status_code == 200: + if response.ok: data = response.json() assignment.taskbase_id = data['id'] assignment.save() @@ -61,10 +67,10 @@ class TaskbaseClient: response = requests.post('{}/api/task/{}'.format(self.base_url, assignment.taskbase_id), json=payload, headers=headers) - if response.status_code != 200: - raise TaskbaseException('Something went wrong') + if not response.ok: + raise TaskbaseException(f'Something went wrong - {response.status_code}: {response.reason} - {response.text}') else: # todo: define what to do here - raise TaskbaseException('Something went wrong') + raise TaskbaseException(f'Something went wrong - {response.status_code}: {response.reason} - {response.text}') def spellcheck(self, task, text): if self.token is None: