add check that token request succeeded before parsing response as json