Added a check to see if login was successful before attempting to retrieve the response document