From e8ff4a1c4015049503ee5e1bb72ceac34d286e13 Mon Sep 17 00:00:00 2001 From: adriant Date: Wed, 24 Feb 2016 17:41:01 +1300 Subject: [PATCH] Error clean up, error catching, require django <1.9 * cleaning up the error format in this function to match our standard format. * Catching an error that can occur if the json is improperly decoded. * fixing Django to the LTS support version as 1.9.1 breaks our automatic api documentation. Change-Id: Ib3e452427989b376c55710ce33f73fabdc84260d --- requirements.txt | 2 +- stacktask/api/v1/views.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1429999..a88a358 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django>=1.8.9 +Django>=1.8.9,<1.9 decorator>=3.4.0 djangorestframework>=3.0.3 keystonemiddleware>=1.3.1 diff --git a/stacktask/api/v1/views.py b/stacktask/api/v1/views.py index 0288c4f..6019619 100644 --- a/stacktask/api/v1/views.py +++ b/stacktask/api/v1/views.py @@ -684,9 +684,13 @@ class TokenDetail(APIViewWithLogger): data[field] = request.data[field] except KeyError: errors[field] = ["This field is required.", ] + except TypeError: + errors = ["Improperly formated json. " + + "Should be a key-value object.", ] + break if errors: - return Response(errors, status=400) + return Response({"errors": errors}, status=400) for action in actions: try: