Move @has_request_variables error responses to middleware

This will now allow us to use @has_request_variables on helper
functions.

(imported from commit 799d71477654eac7fd8192cfc5bb88b78053532d)
This commit is contained in:
Zev Benjamin
2012-12-19 14:19:46 -05:00
parent d179de07f6
commit bf5ce4783d
4 changed files with 45 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
from decorator import RequestVariableMissingError, RequestVariableConversionError
from zephyr.lib.response import json_error
import logging
import time
@@ -23,3 +26,9 @@ class LogRequests(object):
% (remote_ip, request.method, response.status_code,
time_delta, request.get_full_path()))
return response
class JsonErrorHandler(object):
def process_exception(self, request, exception):
if hasattr(exception, 'to_json_error_msg') and callable(exception.to_json_error_msg):
return json_error(exception.to_json_error_msg())
return None