我们的生产客户正在努力应对以下错误: Office JS API不返回用户标识令牌,这会阻止我们的加载项的全部使用。
我们在日志中看到的错误:
{
"name": "AccessRestricted",
"message": "Internal protocol error: '-2147467259'.",
"code": 9017
}
有时,当笔记本电脑在睡眠模式后醒来时有时会出现,有时则没有。
此外,当我们的代码执行获取用户身份令牌异步时,Office JS API中有时会出现以下错误(但不是每次出现AccessRestricted
错误时):
"Unable to get property 'Execute' of undefined or null reference",
"number": -2146823281,
"stack":
"TypeError: Unable to get property 'Execute' of undefined or null reference
at n.prototype.execute (https://appsforoffice.microsoft.com/lib/1... (truncated by our logging system)
Outlook版本为16.0.8528.2147,并且加载项已固定。 附: Office JS API已初始化,这不是此问题的根本原因。
以下是代码:
sfMailApp.OfficeManager.prototype.getCallbackTokenAsync = function () {
var item = this.getItem();
return !item.isFake ? this._loadItemAsync(Office.context.mailbox, 'getCallbackTokenAsync') : sfMailApp.utils.resolveDeferred('');
};
sfMailApp.OfficeManager.prototype.getIdentityTokenAsync = function (force) {
var ls = getLocalStorage();
var lastUpdateIdentityTokenTimestamp = ls.getItem('identityTokenUpdate');
var cachedIdentityToken = ls.getItem('identityToken');
var lastUpdateIdentityTokenDifference = !sfMailApp.utils.isNullOrEmpty(lastUpdateIdentityTokenTimestamp) ? (new Date().getTime() - parseInt(lastUpdateIdentityTokenTimestamp)) : null;
if (sfMailApp.utils.isNullOrEmpty(cachedIdentityToken) || cachedIdentityToken === 'null' || sfMailApp.utils.isNullOrEmpty(lastUpdateIdentityTokenDifference) || force ||
(lastUpdateIdentityTokenDifference / (1000 * 60)) > sfMailApp.settings.identityTokenUpdateIntervalMinutes) {
var deferred = $.Deferred();
var item = this.getItem();
if (!item.isFake) {
sfMailApp.analytics.trackEvent('LoadUserIdentityTokenAsync', 'Start', {
user: sfMailApp.mailService.userEmail
});
this._loadItemAsync(Office.context.mailbox, 'getUserIdentityTokenAsync').done(function (token) {
ls.setItem('identityTokenUpdate', new Date().getTime());
ls.setItem('identityToken', token);
sfMailApp.sessionManager.setIdentityToken(token);
deferred.resolve(token);
}).fail(function (err) {
ls.setItem('identityTokenUpdate', null);
ls.setItem('identityToken', null);
sfMailApp.analytics.trackEvent('LoadUserIdentityTokenAsync', 'Fail', {
user: sfMailApp.mailService.userEmail,
message: err ? JSON.stringify(err) : 'null'
});
deferred.reject(err);
});
} else {
sfMailApp.analytics.trackEvent('Item', 'Empty', {
user: sfMailApp.mailService.userEmail,
message: 'Error while getting identity token - inbox item is empty'
});
sfMailApp.sessionManager.setIdentityToken(cachedIdentityToken);
return sfMailApp.utils.resolveDeferred(cachedIdentityToken);
}
return deferred.promise();
} else {
sfMailApp.sessionManager.setIdentityToken(cachedIdentityToken);
return sfMailApp.utils.resolveDeferred(cachedIdentityToken);
}
};
sfMailApp.OfficeManager.prototype._loadItemAsync = function (obj, name) {
if (sfMailApp.utils.isCommands() && sfMailApp.isCommandsMagicPixel) {
return sfMailApp.utils.rejectDeferred({
message: 'Async Office JS API should not be called in Commands while inserting MagicPixel'
});
}
var deferred = $.Deferred();
var maxAttempCount = 5;
var attempInterval = 1000;
var attempCount = 0;
var _this = this;
function checkResult(asyncResult) {
var processFunc = function () {
try {
if (_this._checkProperyExists(obj, name)) {
obj[name](checkResult);
} else {
checkResult(null);
}
} catch (e) {
if (name !== 'loadCustomPropertiesAsync' && name !== 'getCallbackTokenAsync') {
sfMailApp.analytics.trackException(e, name + '.Fail', {
user: sfMailApp.mailService.userEmail,
error: e ? JSON.stringify(e) : null
});
}
checkResult(null);
}
}
if ((sfMailApp.utils.isNullOrEmpty(asyncResult) || asyncResult.status !== Office.AsyncResultStatus.Succeeded) && attempCount < maxAttempCount) {
attempCount++;
if (attempCount <= 1) {
processFunc();
} else {
setTimeout(processFunc, attempInterval);
}
} else {
if (asyncResult && asyncResult.status === Office.AsyncResultStatus.Succeeded) {
deferred.resolve(asyncResult.value);
} else {
var params = {
user: sfMailApp.mailService.userEmail
};
if (asyncResult) {
params.status = asyncResult.status;
params.value = asyncResult.value;
params.error = JSON.stringify(asyncResult.error);
}
if (name !== 'loadCustomPropertiesAsync' && name !== 'getCallbackTokenAsync') {
sfMailApp.analytics.trackException(new Error(name + '.Fail'), '', params);
}
deferred.reject(asyncResult);
}
}
}
var inboxItem = this.getItem();
if (obj && !obj.isFake && !inboxItem.isFake) {
checkResult(null);
} else {
deferred.resolve({});
}
return deferred.promise();
};
答案 0 :(得分:0)
感谢您告诉我们,Sviatoslav。我们知道这个问题,目前正在调查它。一旦确定修复,我们将更新此答案!