IVLEError exception standards are ugly and unPythonic
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
IVLE |
Fix Released
|
Medium
|
William Grant |
Bug Description
IVLE apps currently seem to be discouraged from letting any exception
escape them other than an IVLEError. This results in lots of 'except
Exception, e:', which is unthinkably bad.
Lumping all HTTP errors into IVLEError is also very strange. We should
probably instead create a root HTTP error class and subclasses like
BadRequest, NotFound, Forbidden which specify the numeric code and default
message.
For example, what was previously:
req.
becomes:
raise BadRequest('the foo isn't valid')
... which is far more obvious and prettier.
We should also alter the standards to recommend that applications do not
trap errors except those that they know are likely to happen, and are not
crashes.
For example: if an exception is caused by a user specifying a URL argument
with the wrong type, it should be caught and a BadRequest raised. If an
exception occurs during a normal piece of code, it should be allowed to
bubble up to the root handler without being touched by the app.
This should reduce code nesting depth, shorten it somewhat, and allow more
useful error logs - calling req.throw_error() instead of raising directly
causes the traceback and some exception information to be lost.
All views ported to the new dispatch framework have the exceptions corrected.