From 412ae9af9a576a4e6f716ed6482189ec88b0b366 Mon Sep 17 00:00:00 2001 From: parama Date: Mon, 6 May 2024 19:53:41 +0530 Subject: [PATCH] unit test + added attachOriginalToWebAPIRequestError to WebClientOptions --- packages/web-api/src/WebClient.spec.js | 42 +++++++++++++++++++++++++- packages/web-api/src/WebClient.ts | 11 +++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/packages/web-api/src/WebClient.spec.js b/packages/web-api/src/WebClient.spec.js index d74ba7670..7f9f7813f 100644 --- a/packages/web-api/src/WebClient.spec.js +++ b/packages/web-api/src/WebClient.spec.js @@ -2,7 +2,7 @@ require('mocha'); const fs = require('fs'); const path = require('path'); const { Agent } = require('https'); -const { assert } = require('chai'); +const { assert, expect } = require('chai'); const { WebClient, buildThreadTsWarningMessage } = require('./WebClient'); const { ErrorCode } = require('./errors'); const { LogLevel } = require('./logger'); @@ -1612,6 +1612,46 @@ describe('WebClient', function () { }); }); + describe('has an option to suppress request error from Axios', () => { + it('the \'original\' property is attached when the option, attachOriginalToWebAPIRequestError is absent', async () => { + const client = new WebClient(token, { + timeout: 10, + retryConfig: rapidRetryPolicy, + }); + try { + await client.conversations.list() + } catch(err) { + expect(err).to.haveOwnProperty('original') + } + }); + + it('the \'original\' property is attached when the option, attachOriginalToWebAPIRequestError is set to true', async () => { + const client = new WebClient(token, { + timeout: 10, + retryConfig: rapidRetryPolicy, + attachOriginalToWebAPIRequestError: true, + }); + try { + await client.conversations.list() + } catch(err) { + expect(err).to.haveOwnProperty('original') + } + }); + + it('the \'original\' property is not attached when the option, attachOriginalToWebAPIRequestError is set to false', async () => { + const client = new WebClient(token, { + timeout: 10, + retryConfig: rapidRetryPolicy, + attachOriginalToWebAPIRequestError: false, + }); + try { + await client.conversations.list() + } catch(err) { + expect(err).not.to.haveOwnProperty('original') + } + }); + }); + afterEach(function () { nock.cleanAll(); }); diff --git a/packages/web-api/src/WebClient.ts b/packages/web-api/src/WebClient.ts index cd5f1b34c..9aa399bba 100644 --- a/packages/web-api/src/WebClient.ts +++ b/packages/web-api/src/WebClient.ts @@ -70,6 +70,13 @@ export interface WebClientOptions { rejectRateLimitedCalls?: boolean; headers?: Record; teamId?: string; + /** + * Indicates whether to attach the original error to a Web API request error. + * When set to true, the original error object will be attached to the Web API request error. + * @type {boolean} + * @default true + */ + attachOriginalToWebAPIRequestError?: boolean, } export type TLSOptions = Pick; @@ -168,8 +175,8 @@ export class WebClient extends Methods { private teamId?: string; /** - * Configuration to opt-out of attaching the original property to WebAPIRequestError. - * See {@link https://github.com/slackapi/node-slack-sdk/issues/1751} for more details. + * Configuration to opt-out of attaching the original error + * (obtained from the HTTP client) to WebAPIRequestError. */ private attachOriginalToWebAPIRequestError: boolean;