Looking at the internal code, it doesn't look like you can get the "body" argument to HTTP() in the error handler. However, here are a couple of hacks:
request.wsgi.wsgi_environ['error_message'] = 'Explanation Text'
raise HTTP(400)
Then in the error handler:
def error_handler():
error_message = request.env.error_message
That works because request.wsgi.wsgi_environ is the original WSGI environment dictionary for the request, and it gets re-used by the error handler (so it ends up in request.env in the error handler).
Alternatively, you can append your error message to request.url, which itself is passed to the error handler:
request.url = '%s&error_message=%s' % (request.url, 'Explanation Text')
And in the error handler:
def error_handler():
error_message = request.vars.error_message
That is really just adding an additional variable to the query string that gets passed to the error handler by embedding the new variable within request.url.
Alternatively, if you have a limited number of messages, you can simply use a different numeric response code for each case to distinguish the errors. You don't have to limit yourself to the standard HTTP response codes, as in this case, the code is only used internally and never sent to the client (you can set a new response status when finally sending a response to the client).
Anthony