LOAD an routes_onerror

51 views
Skip to first unread message

Annet

unread,
Mar 6, 2018, 3:38:35 AM3/6/18
to web2py-users
In my application I have a view containing a header, main and footer component.
In the index function of a controller I have the following code:

maincomponent = LOAD('home', 'base', args=[vertexID, viewtypeID, groupID, plural],
                         ajax=True, target='main-component', content='')

this loads the home page, all other pages are loaded in the main-component.

I have a separate application which handles errors. In routes.py I have the following
code:


routes_onerror = [
    (r'init/*', r'/error/default/index')
   ,(r'*/404', r'/error/default/index')
   ,(r'*/*', r'/error/default/index')
]

# specify action in charge of error handling

error_handler = dict(application='error',
                     controller='default',
                     function='index')


The problem is that in case of an error the error_handler is being loaded into
the main-component. Which results in the menu in the header displaying
multiple dropdown carets and the menu items not being clickable anymore.

What is the best way to solve this issue?


Kind regards,

Annet

Anthony

unread,
Mar 6, 2018, 2:09:58 PM3/6/18
to web2py-users
Have you tried redirect(..., client_side=True) in your error handler?

Annet

unread,
Mar 16, 2018, 5:25:10 AM3/16/18
to web2py-users
Hi Anthony,

Thanks for your reply.



Have you tried redirect(..., client_side=True) in your error handler?


The error handler  error/default/index contains the following lines of code:


def index():
    session.forget(response)

    response.title = 'Leonexus - Error handler'

    return dict()


I do not have a line redirect(..., client_side=True) in my code. Is it possible to add
client_side = True to error_handler in routes.py


error_handler = dict(application='error',
                     controller='default',
                     function='index',
                     client_side = True)


Kind regards,

Annet

Anthony

unread,
Mar 16, 2018, 11:02:49 AM3/16/18
to web2py-users
The redirect would go in the /error/default/index controller action. It sends a 200 response to the browser with a special header instructing web2py.js to do a client-side redirect (i.e., load a new URL in the address bar).

Anthony
Reply all
Reply to author
Forward
0 new messages