I have a CherryPy v 3.7 application. The application uses expiring sessions to maintain login state.
If the session expires and the user attempts to navigate to a different page (or refresh the current page) the system correctly returns the login page. That works well.
If the session expires and the users performs an action that results in an AJAX request to the server, one of two things happens:
If the request is a GET the endpoint for the login page is called, the login page is rendered and returned to the browser, and replaced in the DOM wherever I'm swapping in the result of the GET.
If the request is a POST the server returns a 500 error, with the stack trace below (indicating that no endpoint in my code was ever called).
Traceback (most recent call last):
File "C:\Users\larry\Envs\auldbrass\lib\site-packages\cherrypy_cprequest.py", line 667, in respond
self.hooks.run('before_handler')
File "C:\Users\larry\Envs\auldbrass\lib\site-packages\cherrypy_cprequest.py", line 114, in run
raise exc
KeyError: 'username'
Neither of these are the correct behavior. Instead, I would like to force the browser to redirect to the login page URL in both cases.
Does anyone know how I can implement this behavior in CherryPy 3.7?