Skip to content

Commit

Permalink
Return a 404 rather than an error page if the key cannot be found.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Sep 4, 2008
1 parent 8367e9a commit 08ce90c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/keas/kmi/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ encryption key string:
>>> len(encKey)
32

If you try to request a nonexistent key, you get a 404 error:
encryption key string:

>>> import cStringIO
>>> io = cStringIO.StringIO('xyzzy')

>>> request = TestRequest(io)
>>> request.method = 'POST'

>>> keyCall = rest.KeyView(keys, request)
>>> print keyCall()
Key not found
>>> request.response.getStatus()
404

A `GET` request to the root shows us a server status page

>>> request = TestRequest()
Expand Down
7 changes: 6 additions & 1 deletion src/keas/kmi/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ def POST(self):
stream.seek(0)
key = stream.read()
self.request.response.setHeader('content-type', 'text/plain')
return self.context.getEncryptionKey(key)
try:
return self.context.getEncryptionKey(key)
except KeyError:
self.request.response.setStatus(404)
return 'Key not found'

0 comments on commit 08ce90c

Please sign in to comment.