-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1404 SocketModeReceiver app process exits when any of its event …
…listeners throws an exception (#1405) Co-authored-by: Fil Maj <maj.fil@gmail.com>
- Loading branch information
Showing
7 changed files
with
163 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
current_dir=`dirname $0` | ||
cd ${current_dir} | ||
npm unlink @slack/bolt \ | ||
&& npm i \ | ||
&& cd ../.. \ | ||
&& npm link \ | ||
&& cd - \ | ||
&& npm i \ | ||
&& npm link @slack/bolt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'mocha'; | ||
import { assert } from 'chai'; | ||
import { SocketModeFunctions as func } from './SocketModeFunctions'; | ||
import { | ||
ReceiverMultipleAckError, | ||
AuthorizationError, | ||
} from '../errors'; | ||
import { createFakeLogger } from '../test-helpers'; | ||
import { ReceiverEvent } from '../types'; | ||
|
||
describe('SocketModeFunctions', async () => { | ||
describe('Error handlers for event processing', async () => { | ||
const logger = createFakeLogger(); | ||
|
||
describe('defaultProcessEventErrorHandler', async () => { | ||
it('should return false if passed any Error other than AuthorizationError', async () => { | ||
const event: ReceiverEvent = { | ||
ack: async () => {}, | ||
body: {}, | ||
}; | ||
const shouldBeAcked = await func.defaultProcessEventErrorHandler({ | ||
error: new ReceiverMultipleAckError(), | ||
logger, | ||
event, | ||
}); | ||
assert.isFalse(shouldBeAcked); | ||
}); | ||
it('should return true if passed an AuthorizationError', async () => { | ||
const event: ReceiverEvent = { | ||
ack: async () => {}, | ||
body: {}, | ||
}; | ||
const shouldBeAcked = await func.defaultProcessEventErrorHandler({ | ||
error: new AuthorizationError('msg', new Error()), | ||
logger, | ||
event, | ||
}); | ||
assert.isTrue(shouldBeAcked); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import type { Logger } from '@slack/logger'; | ||
import { CodedError, ErrorCode } from '../errors'; | ||
import { ReceiverEvent } from '../types'; | ||
|
||
export class SocketModeFunctions { | ||
// ------------------------------------------ | ||
// Error handlers for event processing | ||
// ------------------------------------------ | ||
|
||
// The default processEventErrorHandler implementation: | ||
// Developers can customize this behavior by passing processEventErrorHandler to the constructor | ||
public static async defaultProcessEventErrorHandler( | ||
args: SocketModeReceiverProcessEventErrorHandlerArgs, | ||
): Promise<boolean> { | ||
const { error, logger, event } = args; | ||
// TODO: more details like envelop_id, payload type etc. here | ||
// To make them available, we need to enhance underlying SocketModeClient | ||
// to return more properties to 'slack_event' listeners | ||
logger.error(`An unhandled error occurred while Bolt processed (type: ${event.body.type}, error: ${error})`); | ||
logger.debug(`Error details: ${error}, retry num: ${event.retryNum}, retry reason: ${event.retryReason}`); | ||
const errorCode = (error as CodedError).code; | ||
if (errorCode === ErrorCode.AuthorizationError) { | ||
// The `authorize` function threw an exception, which means there is no valid installation data. | ||
// In this case, we can tell the Slack server-side to stop retries. | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
// The arguments for the processEventErrorHandler, | ||
// which handles errors `await app.processEvent(even)` method throws | ||
export interface SocketModeReceiverProcessEventErrorHandlerArgs { | ||
error: Error | CodedError; | ||
logger: Logger; | ||
event: ReceiverEvent, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters