Added a check to see if the session has been invalidated

Invalidated sessions (e.g. log out clicked) throw an exception and make a mess in the logs so test for them first