Bot Framework对话框中的错误处理 [英] Error handling in Bot Framework dialogs

查看:113
本文介绍了Bot Framework对话框中的错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何捕获对话框中的所有异常?是否有类似ASP.NET异常过滤器的内容? 我想根据异常类型向用户发送不同的消息.

How can I catch all exceptions in dialogs? Is there something like ASP.NET Exception Filter? I want to send different messages to user depending on exception type.

谢谢

推荐答案

您可以使用ExceptionFilter这个事实是正确的.

You are right about the fact that you can use ExceptionFilter.

您只需要执行以下操作:

You just have to do the following:

创建您的ExceptionFilter 类,例如,以在Application Insights中强制跟踪异常(或在您的情况下处理特定的异常类型):

Create your ExceptionFilter class, for example to force the tracking of the exception in Application Insights (or in your case handle specific exception types):

using Microsoft.ApplicationInsights;
using System.Net.Http;
using System.Web.Http.Filters;

namespace BotDemo.App_Start
{
    public class ExceptionFilter : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext ctx)
        {
            HandleError(ctx);
        }

        private static void HandleError(HttpActionExecutedContext ctx)
        {
            ctx.Response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)
            {
                Content = new StringContent(ctx.Exception.Message)
            };

            var client = new TelemetryClient();
            client.TrackException(ctx.Exception);
        }
    }
}

请不要忘记在Application_Start()定义例外过滤器:

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        GlobalConfiguration.Configuration.Filters.Add(new ExceptionFilter());
         ...

就是这样.

实际上Bot Framework模板使用的是ASP.Net,因此您具有所有正常功能.

In fact Bot Framework template is using ASP.Net, so you have all the normal features.

这篇关于Bot Framework对话框中的错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆