Imagine that I have an application called 'myapp' running in my local web2py server, and I include this in routes.py to manage HTTP errors using a custom controller (/myapp/portal/error_page):
routes_onerror = [
('myapp/*', '/myapp/portal/error_page'),
]
Then, when somebody access to myapp and a HTTP exception is raised, web2py framework catches it and redirects execution to my custom controller. Perfect! That is what I was looking for! :)
Debugging function regex_url_in in gluon/rewrite.py I have realised that request.application is None when an "invalid request" error is produced. Then try_redirect_on_error doesn't know which is the application that produces the problem and is not able to redirect execution to the custom controller configured in routes.py.
I wonder if it would have sense to infer request.application from an invalid url to allow custom controller redirection when an invalid request error is produced.
# Maybe adding something like this in gluon.rewrite.regex_url_in?
# ...
match = regex_url.match(path)
if not match:
# Added
application_match = re.search('^/(?P<a>\w+)/.*$', path)
request.application = application_match and application_match.group('a') or None
invalid_url(routes)
request.raw_args = (match.group('s') or '')
if request.raw_args.startswith('/'):
request.raw_args = request.raw_args[1:]
# ...
Thank you very much for web2py :)