Search code examples
pythongoogle-app-enginewebapp2

GAE redirect inside try throws exception


A simple logout redirect handler.

    logging.info(users.create_logout_url(self.request.get('return_url')))
    try:
        return self.redirect(users.create_logout_url(self.request.get('return_url')), abort=True)
    except Exception as e:
        logging.error('Could not Logout user')
        logging.error(repr(e))
        #self.redirect('/')
        return
    #self.redirect('/')

This fails with exception of < HTTPFound at 0xca3e60 302 Moved Temporarily >

if I move the redirect outside the try works.

I am confused.


Solution

  • Calling with abort=True causes HTTPFound to be raised, which is an Exception. If you're worried about create_logout_url erroring, then wrap that with try ... except separately.