better error handling and auto relogin when session expires