Skip to content

Commit

Permalink
Fix webhook fast 404 when getting deleted webhook message
Browse files Browse the repository at this point in the history
  • Loading branch information
bsian03 committed Nov 8, 2024
1 parent 23fc2e7 commit 3a19c10
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/queue.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package lib

import (
"bytes"
"context"
"errors"
"github.com/Clever/leakybucket"
"github.com/Clever/leakybucket/memory"
"github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/Clever/leakybucket"
"github.com/Clever/leakybucket/memory"
"github.com/sirupsen/logrus"
)

type QueueItem struct {
Expand Down Expand Up @@ -272,6 +276,11 @@ func return401(item *QueueItem) {
item.doneChan <- nil
}

func isUnknownWebhook(_body io.ReadCloser) bool {
body, _ := ioutil.ReadAll(_body);
return bytes.Contains(body, []byte("\"code\": 10015"))
}

func isInteraction(url string) bool {
parts := strings.Split(strings.SplitN(url, "?", 1)[0], "/")
for _, p := range parts {
Expand Down Expand Up @@ -348,7 +357,7 @@ func (q *RequestQueue) subscribe(ch *QueueChannel, path string, pathHash uint64)
}).Warn("Unexpected 429")
}

if resp.StatusCode == 404 && strings.HasPrefix(path, "/webhooks/") && !isInteraction(item.Req.URL.String()) {
if resp.StatusCode == 404 && isUnknownWebhook(resp.Body) && !isInteraction(item.Req.URL.String()) {
logger.WithFields(logrus.Fields{
"bucket": path,
"route": item.Req.URL.String(),
Expand Down

0 comments on commit 3a19c10

Please sign in to comment.