Botframework 在NodeJS bot实现中,为什么使用onTurnError而不是自己的try/catch?

Botframework 在NodeJS bot实现中,为什么使用onTurnError而不是自己的try/catch?,botframework,Botframework,在NodeJS bot实现中,我看到BotFrameworkAdapter上有一个onTurnError属性。医生没怎么说。我什么时候会使用该属性与我自己的try/catch? 例如: const adapter = new BotFrameworkAdapter(); adapter.onTurnError = async (context, error) => {  // handle the error }; vs 这个问题问得好,让我好奇,所以我做了一些测试。就我所知,没有区别。

在NodeJS bot实现中,我看到BotFrameworkAdapter上有一个onTurnError属性。医生没怎么说。我什么时候会使用该属性与我自己的try/catch?

例如:

const adapter = new BotFrameworkAdapter();
adapter.onTurnError = async (context, error) => {
 // handle the error
};
vs


这个问题问得好,让我好奇,所以我做了一些测试。就我所知,没有区别。经过一些额外的挖掘后,
botAdapter.onTurnError
除了捕获错误外,什么也做不了

但是,如果您想要执行一些复杂的错误处理,这将为您提供一个处理程序,这样您就不必编写自己的处理程序,而不必执行以下操作:

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        try {
            await myBot.onTurn(context);
        } catch (error) {
            myErrorHandler(error);
        }
    });
});

const myErrorHandler = (error) => {
    // Many lines of complex error handling code
}
你只要做:

adapter.onTurnError = async (context, error) => {
    // Many lines of complex error handling code
};

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await myBot.onTurn(context);
    });
});
只是稍微干净一点

adapter.onTurnError = async (context, error) => {
    // Many lines of complex error handling code
};

server.post('/api/messages', (req, res) => {
    adapter.processActivity(req, res, async (context) => {
        await myBot.onTurn(context);
    });
});