Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix truncated JSON validation error message #401

Merged
merged 2 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cornice/validators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down