Alerting: Fix Teams notifier not failing on 200 response with error (#52254) (#52260)

Team's webhook API does not always use the status code to communicate errors.
There are cases where it returns 200 and an error message in the body.
For example, 429 - Too Many Requests or when the message is too large.
Instead, what we should be looking for is a response body = "1".

https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#send-messages-using-curl-and-powershell
(cherry picked from commit efa0d90093)
This commit is contained in:
Matthew Jacobson
2022-07-14 13:38:21 -04:00
committed by GitHub
parent d8eada0132
commit 1d6190e4ff
8 changed files with 157 additions and 44 deletions
+8
View File
@@ -30,3 +30,11 @@ func NewFakeDisconnectedMailer() *FakeDisconnectedMailer {
func (fdm *FakeDisconnectedMailer) Send(messages ...*Message) (int, error) {
return 0, fmt.Errorf("connect: connection refused")
}
// NetClient is used to export original in test.
var NetClient = &netClient
// SetWebhookClient is used to mock in test.
func SetWebhookClient(client WebhookClient) {
netClient = client
}