Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a StatusCodeError when a workspace's message limit is exceeded #1383

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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