Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

c# - How to avoid "Sorry, my bot code is having an issue" in Microsoft Bot Framework

I have a bot that runs on Azure + Bot Framework + LUIS (via LuisDialog).

If the user happens to send two messages in a quick succession (before the bot has a chance to answer), they see this error message on their Facebook Messenger or web embed:

Sorry, my bot code is having an issue.

When debugging through bot channel emulator, I see that the error is this:

"text": "Error: Response status code does not indicate success: 429 (Too Many Requests). at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.Bot.Builder.Luis.LuisService.d__4.MoveNext()

The end of the stack trace shows that the error originated at this line in my MessageController.cs:

await Conversation.SendAsync(activity, () => new LuisRootDialogEnglish());

This is weird because I'm using a paid version of LUIS which allows up to 10 calls per second.

In any case, I tried wrapping the whole code in MessageController.cs into a try/catch block, and returning this value regardless of an exception:

return Request.CreateResponse(HttpStatusCode.OK);

Still, the users see the error message "Sorry, my bot code is having an issue" which basically means there is an unhandled exception.

How can I prevent this message from being shown to users, or catch the exception?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The message is sent to the user in PostUnhandledExceptionToUserTask only because the exception has escaped the root dialog A. You can avoid this situation by preventing unhandled exceptions from escaping the root dialog A.

One option is to add a different root dialog B that simply calls your dialog A and then simply ignores the IAwaitable<R> result that is passed to the ResumeAfter<R> callback.

Chain.DefaultIfException provides an implementation of dialog B.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...