Skip to content

Commit f2f26bd

Browse files
authored
Add a type predicate for CodedError, fixing a typescript error that appeared in main somehow. (#2110)
1 parent 65413b9 commit f2f26bd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/App-built-in-middleware.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sinon, { SinonSpy } from 'sinon';
33
import { assert } from 'chai';
44
import rewiremock from 'rewiremock';
55
import { Override, mergeOverrides, createFakeLogger, delay } from './test-helpers';
6-
import { ErrorCode, UnknownError, AuthorizationError, CodedError } from './errors';
6+
import { ErrorCode, UnknownError, AuthorizationError, CodedError, isCodedError } from './errors';
77
import {
88
Receiver,
99
ReceiverEvent,
@@ -354,9 +354,10 @@ describe('App built-in middleware and mechanism', () => {
354354
// Assert
355355
assert(fakeErrorHandler.calledOnce);
356356
const error = fakeErrorHandler.firstCall.args[0];
357-
assert.instanceOf(error, Error);
357+
assert.ok(isCodedError(error));
358358
assert(error.code === ErrorCode.MultipleListenerError);
359-
assert.sameMembers(error.originals, errorsToThrow);
359+
assert.isArray(error.originals);
360+
if (error.originals) assert.sameMembers(error.originals, errorsToThrow);
360361
});
361362

362363
it('should detect invalid event names', async () => {

src/errors.ts

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export interface CodedError extends Error {
1010
res?: ServerResponse; // HTTPReceiverDeferredRequestError
1111
}
1212

13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14+
export function isCodedError(err: any): err is CodedError {
15+
return 'code' in err;
16+
}
17+
1318
export enum ErrorCode {
1419
AppInitializationError = 'slack_bolt_app_initialization_error',
1520
AuthorizationError = 'slack_bolt_authorization_error',

0 commit comments

Comments
 (0)