From 1be87504ce5bfa034f81dcb9279bcc730344b177 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 21 Oct 2016 16:39:38 +0200 Subject: [PATCH 1/2] Fix truncated JSON validation error message --- CHANGES.txt | 5 ++++- cornice/validators/__init__.py | 4 ++-- tests/test_validation.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1526d828..f00a3b53 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,7 +6,10 @@ CHANGELOG 2.1.0 (unreleased) ================== -- Nothing changed yet. +**Bug fixes** + +- Fix truncated JSON validation error message when request body does not contain + valid JSON 2.0.0 (2016-10-20) diff --git a/cornice/validators/__init__.py b/cornice/validators/__init__.py index 4b10c105..25a399d5 100755 --- a/cornice/validators/__init__.py +++ b/cornice/validators/__init__.py @@ -28,8 +28,8 @@ def extract_cstruct(request): if request.body: try: body = request.json_body - except ValueError: - request.errors.add('body', '', 'Invalid JSON') + except ValueError as e: + request.errors.add('body', '', 'Invalid JSON: %s' % e) return {} else: if not hasattr(body, 'items'): diff --git a/tests/test_validation.py b/tests/test_validation.py index 398f9404..bf9988a2 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -379,7 +379,7 @@ def test_invalid_json(self): status=400) self.assertEqual(response.json['status'], 'error') error_description = response.json['errors'][0]['description'] - self.assertIn('Invalid JSON', error_description) + self.assertIn('Invalid JSON: Expecting object', error_description) def test_json_text(self): app = self.make_ordinary_app() From 9f016e2329f683e9704d8153704cb306936089b0 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Fri, 21 Oct 2016 17:26:11 +0200 Subject: [PATCH 2/2] Fix test under python3 --- tests/test_validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_validation.py b/tests/test_validation.py index bf9988a2..1fcaa9ab 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -379,7 +379,7 @@ def test_invalid_json(self): status=400) self.assertEqual(response.json['status'], 'error') error_description = response.json['errors'][0]['description'] - self.assertIn('Invalid JSON: Expecting object', error_description) + self.assertIn('Invalid JSON: Expecting', error_description) def test_json_text(self): app = self.make_ordinary_app()