okay, so here it is.

in routes.py:
    use_error_controller = True

in main.py (line 218):

# ##################################################
# access the requested application
# ##################################################

if not os.path.exists(request.folder):
    if request.application=='init':
        request.application = 'welcome'
        redirect(html.URL(r=request))
    use_error_controller = rewriteSymbols.get('use_error_controller',
None)
    if use_error_controller == True:
        request.application = 'error'
        request.controller = 'default'
        request.function = 'index'
        request.folder = os.path.join(request.env.web2py_path,
                                      'applications',
request.application) + '/'
    else:
        raise HTTP(400, error_message,
                   web2py_error='invalid application')

and then in error/default/index I can query the database for content
where url=request.path_info

On 26 mai, 22:45, desfrenes <[email protected]> wrote:
> In other words, the question would be "how do I intercept 400+ errors
> before the reponse is sent to the browser".
>
> Diggin' web2py's code (main.py, line 226) I found an possible way to
> do it:
>
> # ##################################################
> # access the requested application
> # ##################################################
>
> if not os.path.exists(request.folder):
>     if request.application=='init':
>         request.application = 'welcome'
>         redirect(html.URL(r=request))
>
>     #
>     # No url match so, if set in config (routes.py?),
>     # call special controller/method handler here (error/error).
>     #
>     # [call method here]
>     #
>     # If not set, go on with standard error http error:
>     #
>
>     raise HTTP(400, error_message,
>                web2py_error='invalid application')
>
> I lack in-depth knowledge of web2py's internals but I'll try to
> implement this and send a patch.
>
> -
>
> On 26 mai, 21:57, mdipierro <[email protected]> wrote:
>
> > Not sure I completely understand the issue but as long as it is ok
> > with you fine.
>
> > On May 26, 2:32 pm, desfrenes <[email protected]> wrote:
>
> > > Thanks.
>
> > > I first played with routes_onerror but it was useless for me since it
> > > affects only redirection (I needed to trap the error *before*
> > > redirection occurs).
>
> > > Then I found this 
> > > thread:http://groups.google.com/group/web2py/browse_thread/thread/95910208a4...
>
> > > Using a regexp to map .html urls to a controller is ok and I will
> > > probably use that, but it means the url still has to have ".html" in
> > > it, thus not reaching the goal of having a complete arbitrary url. But
> > > it's ok though.
>
> > > On 26 mai, 08:17, mdipierro <[email protected]> wrote:
>
> > > > There may be an easier to implement Djangoflatpagesin web2py but if
> > > > you need to trap error codes, look into
>
> > > > web2py/routes.examples.py
>
> > > > Massimo
>
> > > > On May 26, 12:51 am, desfrenes <[email protected]> wrote:
>
> > > > > Hello,
>
> > > > > I'm trying to build something similar to the flatpage application in
> > > > > django, that is an app that maps a simple content to an arbitrary url.
> > > > > To do so I have to trap 400 and 404 errors and then see if a content
> > > > > is attached to this url. If so, display it, if not, raise the error
> > > > > again.
>
> > > > > How can I trap 400 and 404 errors ?
>
> > > > > Cheers
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to