Skip to content

Commit

Permalink
Make sure we handle connection error properly for D3C
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Feb 27, 2024
1 parent 4943560 commit 4fd0863
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion handlers/dialog360/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,10 @@ func (h *handler) requestD3C(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
17 changes: 17 additions & 0 deletions handlers/dialog360/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,23 @@ var SendTestCasesD3C = []OutgoingTestCase{
},
ExpectedError: courier.ErrFailedWithReason("130429", "(#130429) Rate limit hit"),
},
{
Label: "Error Connection",
MsgText: "Error",
MsgURN: "whatsapp:250788123123",
MockResponses: map[string][]*httpx.MockResponse{
"https://waba-v2.360dialog.io/messages": {
httpx.NewMockResponse(500, nil, []byte(`Bad gateway`)),
},
},
ExpectedRequests: []ExpectedRequest{
{
Path: "/messages",
Body: `{"messaging_product":"whatsapp","recipient_type":"individual","to":"250788123123","type":"text","text":{"body":"Error","preview_url":false}}`,
},
},
ExpectedError: courier.ErrConnectionFailed,
},
}

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

0 comments on commit 4fd0863

Please sign in to comment.