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! :)

This works great most of the time, but I have observed that execution 
doesn't go through my custom controller when an "invalid request" error is 
produced (HTTP 400 error code). This happens for example, when I use a 
controller or a function name with special chars like '-'. Ex: 
http://127.0.0.1:8000/myapp/not-existing-controller-with-especial-chars

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 :)

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to