Skip to content

Commit

Permalink
Return a StatusCodeError when a workspace's message limit is exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
greysteil committed Mar 10, 2025
1 parent 5243bef commit e356192
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func timerReset(t *time.Timer, d time.Duration) {
}

func checkStatusCode(resp *http.Response, d Debug) error {
if resp.StatusCode == http.StatusTooManyRequests {
if resp.StatusCode == http.StatusTooManyRequests && resp.Header.Get("Retry-After") != "" {
retry, err := strconv.ParseInt(resp.Header.Get("Retry-After"), 10, 64)
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ func TestPostWebhook_NotOK(t *testing.T) {
}
}

func TestPostWebhook_MessageLimitExceeded(t *testing.T) {
once.Do(startServer)

http.HandleFunc("/message_limit_exceeded", func(rw http.ResponseWriter, r *http.Request) {
// When a workspace's message limit is exceeded we get a 429 without a Retry-After header
rw.WriteHeader(http.StatusTooManyRequests)
rw.Write([]byte("message_limit_exceeded"))
})

url := "http://" + serverAddr + "/message_limit_exceeded"

err := PostWebhook(url, &WebhookMessage{})

if err == nil {
t.Errorf("Expected to receive error")
}
assert.IsType(t, StatusCodeError{}, err)
}

func TestWebhookMessage_WithBlocks(t *testing.T) {
textBlockObject := NewTextBlockObject("plain_text", "text", false, false)
sectionBlock := NewSectionBlock(textBlockObject, nil, nil)
Expand Down

0 comments on commit e356192

Please sign in to comment.