Fail on errors returned from the Slack API when using API Token #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
step.yml
andREADME.md
is updated with the changes (if needed)Version
Requires a PATCH version update
Context
In #44 the Step was updated to support both legacy (fire and forget) webhooks as well as the
chat.postMessage
API method that is part of the Slack API (via the API Token). With this, there is a bit of a change of how errors are reported.The legacy webhook would just fail if it wasn't valid and generally a HTTP 200 response indicated that it sent the message, which lines up with the logic that currently exists:
steps-slack-message/main.go
Lines 154 to 160 in b38da23
However the Slack API does not work in the same way. Failures to send messages still result in a HTTP 200 response and instead the status is described as part JSON response. For example, if we make a request with an invalid token:
With the current implementation this means that Bitrise will continue as if the Slack message had sent successfully even if it didn't. This coupled with Slack apps being easy to misconfigure means that we can often end up spending a lot of extra time trying to work out what went wrong when it would be really helpful to have that error printed to us.
Some other use cases that I ran into during my time configuring things:
api_token
was invalid (invalid_auth
)channel_not_found
)invalid_scopes
)Changes
To improve this, my aim is to always attempt to parse the JSON response when using
api_token
. Ifok
isfalse
, we fail and include theerror
in the message.While #82 updated the step to start parsing the response, it would only do it conditionally if the
output_thread_ts
was set so I have also made additional changes to account for this.As part of this change, instead of erroring if you incorrectly use
output_thread_ts
andwebhook_url
after* the request is sent, I moved the check into the existingvalidate
method that runs after loading theConfig
.Investigation details
Decisions