Fixed bug with closing session before extracting error message.