Open momocow opened 2 years ago
By calling manually await ctx.handlerDidEnd()
the problem can be fixed. (The bot manages to reply the error.)
module.exports = async function handleError(ctx, props) {
await ctx.replyText('something wrong 😰');
console.error(props.error);
console.log(ctx);
await ctx.handlerDidEnd?.();
};
Describe the bug A clear and concise description of what the bug is.
Using Line platform, replying text in the error handler (aka
_error.js
) did not actually send replied text to Line following the guide for error handling in Line.To Reproduce Steps to reproduce the behavior:
Make the entry action throw an Error. (
index.js
)Set up error handler in
_error.js
.Trigger the action by saying anything to the bot.
Nothing is replied from the bot, but in the console we can see the error and the context printed.
I found that on the context object,
ctx._shouldBatch
is still true which will cause all calls toctx.replyText()
buffered.Expected behavior A clear and concise description of what you expected to happen.
The bot should reply "something wrong 😰".
Additional context Add any other context about the problem here.
Since the
ctx.handlerDidEnd()
was skipped (as the following snippet) while the error happened and alsoctx._shouldBatch
was stilltrue
, the reply was left in the buffer without sending it out.https://github.com/Yoctol/bottender/blob/7c400c77d829552d99073b6fb29b2318d2927248/packages/bottender/src/bot/Bot.ts#L287-L298