Ticket #733 (defect)
Opened 1 year ago
Last modified 4 weeks ago
404 instead of 500 on wrong number of arguments
Status: closed (fixed)
| Reported by: | fumanchu | Assigned to: | fumanchu |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.2 |
| Component: | CherryPy code | Keywords: | |
| Cc: |
Currently, calling a handler with the wrong number of arguments results in a 500 error. A 404 might be better. The following patch (against trunk) tries to do this:
Index: _cpdispatch.py
===================================================================
--- _cpdispatch.py (revision 1716)
+++ _cpdispatch.py (working copy)
@@ -21,7 +21,14 @@
self.kwargs = kwargs
def __call__(self):
- return self.callable(*self.args, **self.kwargs)
+ try:
+ return self.callable(*self.args, **self.kwargs)
+ except TypeError, x:
+ import re
+ if re.match(r'%s\(\) takes .+ arguments? \(.+ given\)' %
+ re.escape(self.callable.__name__), x.args[0]):
+ raise cherrypy.HTTPError(404)
+ raise
class LateParamPageHandler(PageHandler):
Attachments
Change History
09/21/07 11:23:56: Modified by fumanchu
- status changed from new to assigned.
10/26/07 00:45:34: Modified by fumanchu
- milestone changed from 3.1 to 3.2.
08/03/08 18:48:01: Modified by lakin
- attachment 400_404_arg_diff.txt added.
Implementation of 400 and 404's when appropriate. With tests.
08/03/08 18:50:12: Modified by lakin
Added a new version that updates the documentation. It also refactors the method into the global name space so that it can be re-used in other dispatchers. The code has been marginally simplified in a few places.
08/04/08 11:32:36: Modified by lakin
- status changed from assigned to closed.
- resolution set to fixed.
Fixed in [2030]


Here's a better one:
Not sure what to do about the mixing of querystring and entity params...is half a solution better than none? or worse?