Skip to content

Commit

Permalink
Merge pull request #707 from nyaruka/send-errors
Browse files Browse the repository at this point in the history
Make sure we handle connection error properly for WAC
  • Loading branch information
rowanseymour authored Feb 27, 2024
2 parents e733583 + eb07c98 commit eadf5a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion handlers/meta/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,11 @@ func (h *handler) requestWAC(payload whatsapp.SendRequest, accessToken string, r
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")

_, respBody, _ := h.RequestHTTP(req, clog)
resp, respBody, err := h.RequestHTTP(req, clog)
if err != nil || resp.StatusCode/100 == 5 {
return courier.ErrConnectionFailed
}

respPayload := &whatsapp.SendResponse{}
err = json.Unmarshal(respBody, respPayload)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,17 @@ var whatsappOutgoingTests = []OutgoingTestCase{
},
ExpectedError: courier.ErrFailedWithReason("130429", "(#130429) Rate limit hit"),
},
{
Label: "Error Connection",
MsgText: "Error",
MsgURN: "whatsapp:250788123123",
MockResponses: map[string][]*httpx.MockResponse{
"*/12345_ID/messages": {
httpx.NewMockResponse(500, nil, []byte(`Bad Gateway`)),
},
},
ExpectedError: courier.ErrConnectionFailed,
},
}

func TestWhatsAppOutgoing(t *testing.T) {
Expand Down

0 comments on commit eadf5a7

Please sign in to comment.