Added check for j===undefined in case token is missing

An exception was thrown if token is not specified in the headers or elsewhere (j===undefined). I added check for that and now REST API returns proper error status code and message.