Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 7f6b555

Browse files
Batta32VictorGrycuk
authored andcommitted
[TypeScript][Skill] Add onTurnError handler (#2900)
* Add onTurnError to catch previously uncaught error * Add onTurnContext to Skill generator template * Update defaultAdapter removing i18next Co-authored-by: Victor Grycuk <[email protected]>
1 parent cbfe565 commit 7f6b555

File tree

2 files changed

+28
-0
lines changed
  • templates/Virtual-Assistant-Template/typescript

2 files changed

+28
-0
lines changed

templates/Virtual-Assistant-Template/typescript/generator-botbuilder-assistant/generators/skill/templates/sample-skill/src/adapters/defaultAdapter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import {
7+
ActivityTypes,
78
AutoSaveStateMiddleware,
89
BotFrameworkAdapter,
910
BotFrameworkAdapterSettings,
@@ -13,6 +14,7 @@ import {
1314
TelemetryLoggerMiddleware,
1415
TranscriptLoggerMiddleware,
1516
TranscriptStore,
17+
TurnContext,
1618
UserState} from 'botbuilder';
1719
import { AzureBlobTranscriptStore } from 'botbuilder-azure';
1820
import {
@@ -30,6 +32,18 @@ export class DefaultAdapter extends BotFrameworkAdapter {
3032
) {
3133
super(adapterSettings);
3234

35+
this.onTurnError = async (context: TurnContext, error: Error): Promise<void> => {
36+
await context.sendActivity({
37+
type: ActivityTypes.Trace,
38+
text: error.message || JSON.stringify(error)
39+
});
40+
await context.sendActivity({
41+
type: ActivityTypes.Trace,
42+
text: error.stack
43+
});
44+
telemetryClient.trackException({ exception: error });
45+
};
46+
3347
if (settings.blobStorage === undefined) {
3448
throw new Error('There is no blobStorage value in appsettings file');
3549
}

templates/Virtual-Assistant-Template/typescript/samples/sample-skill/src/adapters/defaultAdapter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import {
7+
ActivityTypes,
78
AutoSaveStateMiddleware,
89
BotFrameworkAdapter,
910
BotFrameworkAdapterSettings,
@@ -13,6 +14,7 @@ import {
1314
TelemetryLoggerMiddleware,
1415
TranscriptLoggerMiddleware,
1516
TranscriptStore,
17+
TurnContext,
1618
UserState} from 'botbuilder';
1719
import { AzureBlobTranscriptStore } from 'botbuilder-azure';
1820
import {
@@ -30,6 +32,18 @@ export class DefaultAdapter extends BotFrameworkAdapter {
3032
) {
3133
super(adapterSettings);
3234

35+
this.onTurnError = async (context: TurnContext, error: Error): Promise<void> => {
36+
await context.sendActivity({
37+
type: ActivityTypes.Trace,
38+
text: error.message || JSON.stringify(error)
39+
});
40+
await context.sendActivity({
41+
type: ActivityTypes.Trace,
42+
text: error.stack
43+
});
44+
telemetryClient.trackException({ exception: error });
45+
};
46+
3347
if (settings.blobStorage === undefined) {
3448
throw new Error('There is no blobStorage value in appsettings file');
3549
}

0 commit comments

Comments
 (0)