diff --git a/edx_proctoring/backends/rest.py b/edx_proctoring/backends/rest.py index e7f75964ecf..2ded1b741c2 100644 --- a/edx_proctoring/backends/rest.py +++ b/edx_proctoring/backends/rest.py @@ -338,5 +338,10 @@ def _make_attempt_request(self, exam, attempt, method='POST', status=None, **pay if method == 'GET': headers.update(self._get_language_headers()) log.debug('Making %r attempt request at %r', method, url) - response = self.session.request(method, url, json=payload, headers=headers).json() - return response + response = self.session.request(method, url, json=payload, headers=headers) + try: + data = response.json() + except ValueError: + log.exception("Decoding attempt %r -> %r", attempt, response.content) + data = {} + return data diff --git a/edx_proctoring/backends/tests/test_rest.py b/edx_proctoring/backends/tests/test_rest.py index 2a660b7df0e..26a0c865ef2 100644 --- a/edx_proctoring/backends/tests/test_rest.py +++ b/edx_proctoring/backends/tests/test_rest.py @@ -242,6 +242,18 @@ def test_update_exam_attempt_status(self, provider_method_name, corresponding_st status = getattr(self.provider, provider_method_name)(self.backend_exam['external_id'], attempt_id) self.assertEqual(status, corresponding_status) + @responses.activate + def test_failed_json(self): + attempt_id = 2 + responses.add( + responses.PATCH, + url=self.provider.exam_attempt_url.format(exam_id=self.backend_exam['external_id'], attempt_id=attempt_id), + body='"]' + ) + status = self.provider.mark_erroneous_exam_attempt(self.backend_exam['external_id'], attempt_id) + # the important thing is that it didn't raise an exception for bad json + self.assertEqual(status, None) + @responses.activate def test_remove_attempt(self): attempt_id = 2