Salesforce API会话过期,如何自动重新连接
我正在使用节点模块jsforce将销售线索添加到销售线索表。 https://www.npmjs.org/package/node-salesforce这里是文档。 该网站现在是活的,但每天我不得不重新启动服务器会话过期,我收到这个消息
{ [INVALID_SESSION_ID: Session expired or invalid] name: 'INVALID_SESSION_ID', errorCode: 'INVALID_SESSION_ID' } undefined
以下是设置它的代码部分:
conn.sobject("Lead").create({ email : req.body.email, firstname : req.body.first_name, lastname : req.body.last_name, title : req.body.job_title, company : req.body.company, leadsource: 'Clearing Microsite', description: req.body.message }, function(err, ret) { if (err || !ret.success) { return console.error(err, ret); } console.log("Created record id : " + ret.id); }); });
我猜测return console.error(err, ret)
是捕获会话过期,但如何才能重新连接后发生?
我已经尝试使用conn.logout
然后重新login,与loginfunction,但不能得到它的工作,这是很难testing,因为它似乎只有一天后过期!
编辑:我想我需要的东西像if (err == {[INVALID...]}) {reconnect}
但我只是不知道该怎么用
想想我可能已经解决了,在if (err || !ret.success) {}
我补充说:
if (err.name == 'INVALID_SESSION_ID') { conn.logout(function (err) { if (err) { return console.error(err); } conn.login(*login details*) // then repeated the lead entry }); }
我不能检查,看看这是否工作,直到明天早上会议超时,但会更新,如果它的工作/没有
编辑:没有工作,要尝试没有注销。 得到这个错误
[Error: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key: <KEY> This is expected, it can happen if the session has expired and swept away, or if the user logs out, or if its just someone trying to hack in. ]
第二编辑:取出注销工作就像一个魅力! 谢谢@superfell