Skip to content

Commit

Permalink
unit test + added attachOriginalToWebAPIRequestError to WebClientOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Parama92 committed May 6, 2024
1 parent 5ef74d7 commit 412ae9a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
42 changes: 41 additions & 1 deletion packages/web-api/src/WebClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
});
Expand Down
11 changes: 9 additions & 2 deletions packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export interface WebClientOptions {
rejectRateLimitedCalls?: boolean;
headers?: Record<string, string>;
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<SecureContextOptions, 'pfx' | 'key' | 'passphrase' | 'cert' | 'ca'>;
Expand Down Expand Up @@ -168,8 +175,8 @@ export class WebClient extends Methods {
private teamId?: string;

Check failure on line 176 in packages/web-api/src/WebClient.ts

View workflow job for this annotation

GitHub Actions / test (18.x, packages/web-api)

Trailing spaces not allowed

Check failure on line 176 in packages/web-api/src/WebClient.ts

View workflow job for this annotation

GitHub Actions / test (20.x, packages/web-api)

Trailing spaces not allowed
/**
* 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;

Expand Down

0 comments on commit 412ae9a

Please sign in to comment.