-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
providing a way to disable message content being logged #1786
providing a way to disable message content being logged #1786
Conversation
Thanks for the contribution! Before we can merge this, we need @Parama92 to sign the Salesforce Inc. Contributor License Agreement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I left a comment about documenting the new option in WebClientOptions
.
We will also require a unit test for this option before we can accept this PR, please 🙇 🙏
Thanks for the feedback! I have addressed the comments and have re-requested a review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Very close, all I ask is that we mock out Slack API responses in the tests that you added. I provided details in my comment in-line.
Thanks again for working on this!
@@ -1612,6 +1612,46 @@ describe('WebClient', function () { | |||
}); | |||
}); | |||
|
|||
describe('has an option to suppress request error from Axios', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these tests!
One thing we should do is ensure we mock out any calls to the slack.com API. Right now, since your tests are actually invoking e.g. conversations.list()
method, this is issuing an HTTP request to slack.com/api. Not great, as we are a) unnecessarily creating traffic for Slack and b) have less control over the outcome of our tests. What if, during a test run, the Slack API goes down? Should the tests fail because of some service degradation? Probably not.
To handle this, we use the nock
module to mock out API calls. Take a look at the nock setup and use on lines 150-175 of this file. Using nock
, we can finely control a 'fake' response from the Slack API. This way, our tests will avoid both problems a) and b) above!
Additionally, since you have total control over the "Slack API" response using nock
, you can not only test for the presence (and absence) of the original
property in the test, you can even make sure that its contents are what you expect (since you control the API response).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! I understand. That does make sense.
I appreciate you taking the time to review this, share your thoughts, and explain the importance of each change. I apologize for any misunderstanding or oversight in my initial attempts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries at all! Zero judgment on our side, we appreciate you taking the time to send the PR and the improvements; the least we could do is help guide you along in the journey as we try to keep the quality and testing level of the project high working together 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me, let's just make sure the linting and tests pass. On your machine locally, from the web-api
directory, try running npm it
to install the dependencies as well as run the web-api tests. It seems like a few lint rules failed (spacing and other style considerations).
I have addressed the issues that caused the linter to fail. It is running fine on my local machine now. Do you mind running the workflow once again? |
Hmm, seems like the tests are still failing. It looks to me like something is blocking the testing process; see the CI output here. I can also reproduce this behaviour locally on my macbook pro using node v20. |
I believe what is happening is that, because in the tests we return an error / a non-200 HTTP response, As per our documentation on retries, try setting this option in the tests on WebClient to turn off retries:
|
It's also a good idea to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woohoo! Thank you so much for your contribution!
Summary
In this PR, we aim to prevent the logging of message content when a request error occurs while attempting to invoke any of Slack's web APIs.
It solves this issue.
The problem at a glace -
The Error type -
WebAPIRequestError
, contains a property calledoriginal
which holds the raw error received fromaxios
.The
config
property within thisoriginal
is a part of the error data received fromaxios
.This
config
property might in turn hold adata
property, which is the "message" we are trying to opt-out of showing.Tests conducted -
Error log with the opt-out config -
Note: The
original
property is missing from the Error object.Error log without adding the config -
Note: The
original
property is present in the Error object along with all the details of the request.Requirements