diff --git a/handlers/dialog360/handler.go b/handlers/dialog360/handler.go index 3b15e8142..e2b14d522 100644 --- a/handlers/dialog360/handler.go +++ b/handlers/dialog360/handler.go @@ -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 { diff --git a/handlers/dialog360/handler_test.go b/handlers/dialog360/handler_test.go index 983bda5c4..09b6af155 100644 --- a/handlers/dialog360/handler_test.go +++ b/handlers/dialog360/handler_test.go @@ -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) {