app = ExceptionHandlingApplication(urls, globals(), autoreload=True)
Then here's that class:
class ExceptionHandlingApplication(web.application):
"""
This is an overload of the standard web.application class.
Main reason? In application.py, the 'handle_with_processors' function
converts *any* exception into the generic web.py _InternalError.
This interferes, because we wanna trap the original error an make determinations
on how to reply to the client.
So, we overloaded the function and fixed the error handing.
"""
def handle_with_processors(self):
def process(processors):
try:
if processors:
p, processors = processors[0], processors[1:]
return p(lambda: process(processors))
else:
return self.handle()
except (web.HTTPError, KeyboardInterrupt, SystemExit):
raise
except InfoException as ex:
# I use a custom HTTP status code to indicate 'information' back to the user.
web.ctx.status = "280 Informational Response"
logger.exception(ex.__str__())
return ex.__str__()
except SessionError as ex:
logger.exception(ex.__str__())
# now, all our ajax calls are from jQuery, which sets a header - X-Requested-With
# so if we have that header, it's ajax, otherwise we can redirect to the login page.
# a session error means we kill the session
session.kill()
if web.ctx.env.get("HTTP_X_REQUESTED_WITH") == "XMLHttpRequest":
web.ctx.status = "480 Session Error"
return ex.__str__()
else:
logger.debug("Standard Request - redirecting to the login page...")
raise web.seeother('/static/login.html')
except Exception as ex:
# web.ctx.env.get('HTTP_X_REQUESTED_WITH')
web.ctx.status = "400 Bad Request"
logger.exception(ex.__str__())
return ex.__str__()
return process(self.processors)
--
You received this message because you are subscribed to the Google Groups "web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webpy+un...@googlegroups.com.
To post to this group, send email to we...@googlegroups.com.
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.