Skip to content

Commit

Permalink
fix(teams): error crashing server (#370)
Browse files Browse the repository at this point in the history
* fix(teams): error crashing server

* fix error handler

* fix error handler

* bump legacy channels

* bump legacy channels again
  • Loading branch information
samuelmasse committed Feb 17, 2022
1 parent fe2a3c9 commit 46269bc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
7 changes: 5 additions & 2 deletions packages/channels/src/base/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ export class ChannelApiManager {
protected asyncMiddleware(fn: Middleware<Request>) {
return (req: Request, res: Response, next: NextFunction) => {
fn(req, res, next).catch((e) => {
this.logger?.error(`Error occurred calling route ${req.originalUrl}`, e)
return res.sendStatus(500)
this.logger?.error(e, `Error occurred calling route ${req.originalUrl}`)

if (!res.headersSent) {
return res.sendStatus(500)
}
})
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/channels/src/teams/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export class TeamsApi extends ChannelApi<TeamsService> {
private async handleRequest(req: ChannelApiRequest, res: Response) {
const { adapter } = this.service.get(req.scope)

await adapter.processActivity(req, res, async (turnContext) => {
try {
try {
await adapter.processActivity(req, res, async (turnContext) => {
if (this.isProactive(turnContext)) {
await this.handleProactive(req.scope, turnContext)
} else {
await this.handleMessage(req.scope, turnContext)
}
} catch (e) {
this.service.logger?.error(e, 'Error occurred processing teams activity')
}
})
})
} catch (e) {
this.service.logger?.error(e, 'Error occurred processing teams activity')
}
}

private async handleMessage(scope: string, turnContext: TurnContext) {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@botpress/messaging-base": "*",
"@botpress/messaging-channels": "*",
"@botpress/messaging-channels-legacy": "npm:@botpress/messaging-channels@0.1.1",
"@botpress/messaging-channels-legacy": "npm:@botpress/messaging-channels@0.1.3",
"@botpress/messaging-engine": "*",
"@sentry/node": "^6.17.3",
"axios": "^0.25.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/base/auth/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export abstract class AuthHandler {
return (req: Request, res: Response) => {
fn(req, res).catch((e) => {
this.logger.error(e, `Error occurred calling route ${req.originalUrl}`)
return res.sendStatus(500)

if (!res.headersSent) {
return res.sendStatus(500)
}
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2116,9 +2116,9 @@ __metadata:
languageName: unknown
linkType: soft

"@botpress/messaging-channels-legacy@npm:@botpress/messaging-channels@0.1.1":
version: 0.1.1
resolution: "@botpress/messaging-channels@npm:0.1.1"
"@botpress/messaging-channels-legacy@npm:@botpress/messaging-channels@0.1.3":
version: 0.1.3
resolution: "@botpress/messaging-channels@npm:0.1.3"
dependencies:
"@slack/events-api": ^2.3.2
"@slack/interactive-messages": ^1.5.0
Expand All @@ -2139,7 +2139,7 @@ __metadata:
twilio: ^3.67.0
uuid: ^8.3.2
yn: ^4.0.0
checksum: 51976f3afb53dbade8f7afdc9ffd7d6866f3dd09d6632902901e4ce8733e2d759270f4f5de96b81989c822d65fe3e7785eda66ed628b0ba9a3f123accd4478b2
checksum: 04c89f927e252c2d718ea81af0e7d3dc914d071224136dd9093d2454bec1a9f884a80a2c3a7fe3ee7890d257ea30e49679fab69a223209c8442bb8267214bc6b
languageName: node
linkType: hard

Expand Down Expand Up @@ -2286,7 +2286,7 @@ __metadata:
dependencies:
"@botpress/messaging-base": "*"
"@botpress/messaging-channels": "*"
"@botpress/messaging-channels-legacy": "npm:@botpress/messaging-channels@0.1.1"
"@botpress/messaging-channels-legacy": "npm:@botpress/messaging-channels@0.1.3"
"@botpress/messaging-engine": "*"
"@sentry/node": ^6.17.3
"@types/cli-color": ^2.0.2
Expand Down

0 comments on commit 46269bc

Please sign in to comment.