Skip to content

Commit

Permalink
Make all WAC Throttling Errors return courier.ErrConnectionThrottled
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Nov 25, 2024
1 parent 411c508 commit 0c0ed26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion handlers/meta/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"net/http"
"net/url"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -1090,7 +1091,7 @@ func (h *handler) requestWAC(payload whatsapp.SendRequest, accessToken string, r
return courier.ErrResponseUnparseable
}

if respPayload.Error.Code == 131056 {
if slices.Index([]int{4, 80007, 130429, 131048, 131056, 133016}, respPayload.Error.Code) > 0 {
return courier.ErrConnectionThrottled
}

Expand Down
15 changes: 13 additions & 2 deletions handlers/meta/whataspp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,26 @@ var whatsappOutgoingTests = []OutgoingTestCase{
ExpectedError: courier.ErrConnectionThrottled,
},
{
Label: "Error",
Label: "Error Throttled",
MsgText: "Error",
MsgURN: "whatsapp:250788123123",
MockResponses: map[string][]*httpx.MockResponse{
"*/12345_ID/messages": {
httpx.NewMockResponse(403, nil, []byte(`{ "error": {"message": "(#130429) Rate limit hit","code": 130429 }}`)),
},
},
ExpectedError: courier.ErrFailedWithReason("130429", "(#130429) Rate limit hit"),
ExpectedError: courier.ErrConnectionThrottled,
},
{
Label: "Error",
MsgText: "Error",
MsgURN: "whatsapp:250788123123",
MockResponses: map[string][]*httpx.MockResponse{
"*/12345_ID/messages": {
httpx.NewMockResponse(403, nil, []byte(`{ "error": {"message": "(#368) Temporarily blocked for policies violations","code": 368 }}`)),
},
},
ExpectedError: courier.ErrFailedWithReason("368", "(#368) Temporarily blocked for policies violations"),
},
{
Label: "Error Connection",
Expand Down

0 comments on commit 0c0ed26

Please sign in to comment.