Skip to content

Commit

Permalink
providing a way to disable message content being logged
Browse files Browse the repository at this point in the history
  • Loading branch information
Parama92 committed May 3, 2024
1 parent aea11d0 commit 5ef74d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export class WebClient extends Methods {
* This object's teamId value
*/
private teamId?: string;

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

View workflow job for this annotation

GitHub Actions / test (18.x, packages/oauth)

Trailing spaces not allowed

Check failure on line 169 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 169 in packages/web-api/src/WebClient.ts

View workflow job for this annotation

GitHub Actions / test (20.x, packages/oauth)

Trailing spaces not allowed

Check failure on line 169 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.
*/
private attachOriginalToWebAPIRequestError: boolean;

/**
* @param token - An API token to authenticate/authorize with Slack (usually start with `xoxp`, `xoxb`)
Expand All @@ -182,6 +188,7 @@ export class WebClient extends Methods {
rejectRateLimitedCalls = false,
headers = {},
teamId = undefined,
attachOriginalToWebAPIRequestError = true,
}: WebClientOptions = {}) {
super();

Expand All @@ -195,6 +202,7 @@ export class WebClient extends Methods {
this.tlsConfig = tls !== undefined ? tls : {};
this.rejectRateLimitedCalls = rejectRateLimitedCalls;
this.teamId = teamId;
this.attachOriginalToWebAPIRequestError = attachOriginalToWebAPIRequestError;

// Logging
if (typeof logger !== 'undefined') {
Expand Down Expand Up @@ -613,7 +621,7 @@ export class WebClient extends Methods {
const e = error as any;
this.logger.warn('http request failed', e.message);
if (e.request) {
throw requestErrorWithOriginal(e);
throw requestErrorWithOriginal(e, this.attachOriginalToWebAPIRequestError);
}
throw error;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/web-api/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ export function errorWithCode(error: Error, code: ErrorCode): CodedError {
/**
* A factory to create WebAPIRequestError objects
* @param original - original error
* @param attachOriginal - config indicating if 'original' property should be added on the error object
*/
export function requestErrorWithOriginal(original: Error): WebAPIRequestError {
export function requestErrorWithOriginal(original: Error, attachOriginal: boolean): WebAPIRequestError {
const error = errorWithCode(
new Error(`A request error occurred: ${original.message}`),
ErrorCode.RequestError,
) as Partial<WebAPIRequestError>;
error.original = original;
if(attachOriginal) {

Check failure on line 83 in packages/web-api/src/errors.ts

View workflow job for this annotation

GitHub Actions / test (18.x, packages/oauth)

Expected space(s) after "if"

Check failure on line 83 in packages/web-api/src/errors.ts

View workflow job for this annotation

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

Expected space(s) after "if"

Check failure on line 83 in packages/web-api/src/errors.ts

View workflow job for this annotation

GitHub Actions / test (20.x, packages/oauth)

Expected space(s) after "if"

Check failure on line 83 in packages/web-api/src/errors.ts

View workflow job for this annotation

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

Expected space(s) after "if"
error.original = original

Check failure on line 84 in packages/web-api/src/errors.ts

View workflow job for this annotation

GitHub Actions / test (18.x, packages/oauth)

Missing semicolon

Check failure on line 84 in packages/web-api/src/errors.ts

View workflow job for this annotation

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

Missing semicolon

Check failure on line 84 in packages/web-api/src/errors.ts

View workflow job for this annotation

GitHub Actions / test (20.x, packages/oauth)

Missing semicolon

Check failure on line 84 in packages/web-api/src/errors.ts

View workflow job for this annotation

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

Missing semicolon
}
return (error as WebAPIRequestError);
}

Expand Down

0 comments on commit 5ef74d7

Please sign in to comment.