diff --git a/src/errors.ts b/src/errors.ts index 1c6d99e43..7c64fc356 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -4,6 +4,11 @@ import type { BufferedIncomingMessage } from './receivers/verify-request'; /* eslint-disable @typescript-eslint/explicit-member-accessibility */ export interface CodedError extends Error { code: string; // This can be a value from ErrorCode, or WebClient's ErrorCode, or a NodeJS error code + original?: Error; // AuthorizationError, UnknownError + originals?: Error[]; // MultipleListenerError + missingProperty?: string; // ContextMissingPropertyError + req?: IncomingMessage | BufferedIncomingMessage; // HTTPReceiverDeferredRequestError + res?: ServerResponse; // HTTPReceiverDeferredRequestError } export enum ErrorCode { diff --git a/types-tests/error.test-d.ts b/types-tests/error.test-d.ts new file mode 100644 index 000000000..81997f0fa --- /dev/null +++ b/types-tests/error.test-d.ts @@ -0,0 +1,43 @@ +import App from '../src/App'; +import { expectType } from 'tsd'; +import { CodedError } from '../src/errors'; +import { IncomingMessage, ServerResponse } from 'http'; +import { BufferedIncomingMessage } from '../src/receivers/verify-request'; + +const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' }); + +// https://github.com/slackapi/bolt-js/issues/925 +// CodedError should have original and so on +app.error(async (error) => { + expectType(error); + + expectType(error.original); + if (error.original != undefined) { + expectType(error.original); + console.log(error.original.message); + } + + expectType(error.originals); + if (error.originals != undefined) { + expectType(error.originals); + console.log(error.originals); + } + + expectType(error.missingProperty); + if (error.missingProperty != undefined) { + expectType(error.missingProperty); + console.log(error.missingProperty); + } + + expectType(error.req); + if (error.req != undefined) { + expectType(error.req); + console.log(error.req); + } + + expectType(error.res); + if (error.res != undefined) { + expectType(error.res); + console.log(error.res); + } +});