Invalid URI "/services/data/v36.0"
See original GitHub issueCan Somebody explain me , why code 1 fails and gives error <Invalid URI “/services/data/v36.0” > while code 2 passes .
var conn1 = new jsforce.Connection({ oauth2: {
loginUrl: 'sandbox-login-url',
redirectUri: 'sandbox-login-url'
} });
Code 1 conn1.login(‘username’, ‘password’, function (err, userInfo) { if (err) { return console.error(err); } console.log("Org ID 1: " + userInfo.organizationId); });
conn1.identity(function (err, res) { if (err) { return console.error(err); } console.log("user ID conn1: " + res.user_id);
console.log("display name conn1 : " + res.display_name); });
Code 2 conn1.login(‘username’, ‘password’, function (err, userInfo) { if (err) { return console.error(err); } console.log("Org ID 1: " + userInfo.organizationId);
conn1.identity(function (err, res) { if (err) { return console.error(err); } console.log("user ID conn1: " + res.user_id);
console.log("display name conn1 : " + res.display_name); }); });
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top GitHub Comments
@bityogi - using nodejs was only a fun project for me so I could maybe add another useful tool to my toolbox. However the requirement for even simpler javascript programs to be completely callback driven is just too much of a pain to deal with.
Frankly its stupid that the language/ide/environment (whatever of those node is) doesn’t provide a simple opt in/out, or at least is intelligent enough to understand that the program should block until it gets the result of a function when the next line depends on that result.
@shubhamr javascript runs asynchronously. In code1, if identity() call happens before login() is finished, you get ‘Invalid URI’ error. So running code1 you may see error messages (from calling identity()) before a successful "Org ID 1: " message. Code2, the block is in callback, thus has no problem.