首页 > 解决方案 > 解决 Twilio “Uncaught (in promise) t: Error while setting LastConsumedMessageIndex”错误消息

问题描述

在 Wraupup 聊天任务之后,当我从 Twilio Chat API 添加消息时,我收到“Uncaught (in promise) t: Error while setting LastConsumedMessageIndex”错误消息。如果代理在单击 Wraupup 任务按钮后立即单击 Twilio Flex 中的完成任务,则此错误消息将显示在浏览器控制台中。

截屏

我发现这个错误是从作为 Twilio JS SDK 一部分的 sessionerror.js 文件生成的。我无法更改该文件的源代码。如何从我的自定义代码中覆盖它?

这是我在 sessionerror.js 文件中找到的代码:

var SessionError = function (_extendableBuiltin2) {
    (0, _inherits3.default)(SessionError, _extendableBuiltin2);

    function SessionError(message, code) {
        (0, _classCallCheck3.default)(this, SessionError);

        var _this = (0, _possibleConstructorReturn3.default)(this, (SessionError.__proto__ || (0, _getPrototypeOf2.default)(SessionError)).call(this));

        _this.name = _this.constructor.name;
        _this.message = message;
        _this.code = code;
        if (Error.captureStackTrace) {
            Error.captureStackTrace(_this, _this.constructor);
        } else {
            _this.stack = new Error().stack;
        }
        return _this;
    }

    return SessionError;
}(_extendableBuiltin(Error));

exports.SessionError = SessionError;

我怎样才能覆盖这个?

标签: javascriptreactjserror-handlingtwiliotwilio-programmable-chat

解决方案


我刚刚通过使用unhandledrejection事件侦听器解决了我的问题。

使用了以下片段:

window.addEventListener('unhandledrejection', function (event) {
  // ...your code here to handle the unhandled rejection...

  // Prevent the default handling (such as outputting the
  // error to the console)

  event.preventDefault();
});

推荐阅读