- Notifications
You must be signed in to change notification settings - Fork 842
/
Copy pathAdapterWithErrorHandler.cs
33 lines (30 loc) · 1.45 KB
/
AdapterWithErrorHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespaceMicrosoft.Teams.Selfhelp.Authentication.Bot
{
usingMicrosoft.Bot.Builder.Integration.AspNet.Core;
usingMicrosoft.Bot.Builder.TraceExtensions;
/// <summary>
/// Bot error handler middleware.
/// </summary>
publicclassAdapterWithErrorHandler:BotFrameworkHttpAdapter
{
/// <summary>
/// Initializes a new instance of the <see cref="AdapterWithErrorHandler"/> class.
/// Bot adapter handler method.
/// </summary>
/// <param name="configuration">Bot confiruration.</param>
/// <param name="logger">ILogger object.</param>
publicAdapterWithErrorHandler(IConfigurationconfiguration,ILogger<BotFrameworkHttpAdapter>logger)
:base(configuration,logger)
{
OnTurnError=async(turnContext,exception)=>
{
// Log any leaked exception from the application.
logger.LogError($"Exception caught : {exception.Message}");
// Uncomment below commented line for local debugging.
// await turnContext.SendActivityAsync($"Sorry, it looks like something went wrong. Exception Caught: {exception.Message}");
// Send a trace activity, which will be displayed in the Bot Framework Emulator
awaitturnContext.TraceActivityAsync("OnTurnError Trace",exception.Message,"https://www.botframework.com/schemas/error","TurnError");
};
}
}
}