Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #563 from mozilla-services/enhance-if-match-error-…
Browse files Browse the repository at this point in the history
…message

Enhance error message for invalid If-Match headers
  • Loading branch information
leplatrem committed Nov 11, 2015
2 parents a906008 + 0f8b2dc commit beb5645
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cliquet/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,11 @@ def _raise_412_if_modified(self, record=None):
assert if_match[0] == if_match[-1] == '"'
modified_since = int(if_match[1:-1])
except (IndexError, AssertionError, ValueError):
message = ("Invalid value for If-Match. The value should "
"be integer between double quotes.")
error_details = {
'location': 'headers',
'description': "Invalid value for If-Match"
'description': message
}
raise_invalid(self.request, **error_details)
else:
Expand Down
9 changes: 6 additions & 3 deletions cliquet/tests/resource/test_preconditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,12 @@ def test_delete_all_returns_412_if_changed_meanwhile(self):
self.resource.collection_delete)

def test_if_match_without_quotes_raises_invalid(self):
self.resource.request.headers['If-Match'] = '123456'
self.assertRaises(httpexceptions.HTTPBadRequest,
self.resource.collection_get)
with self.assertRaises(httpexceptions.HTTPBadRequest) as cm:
self.resource.request.headers['If-Match'] = '123456'
self.resource.collection_get()
expected_message = ('headers: Invalid value for If-Match. The value '
'should be integer between double quotes.')
self.assertEquals(cm.exception.json['message'], expected_message)

def test_if_match_empty_raises_invalid(self):
self.resource.request.headers['If-Match'] = '""'
Expand Down

0 comments on commit beb5645

Please sign in to comment.