Skip to content

Commit

Permalink
Make RateLimitError implement error rather
Browse files Browse the repository at this point in the history
  • Loading branch information
LHeggy authored Apr 17, 2024
1 parent 85875d8 commit 3a8b107
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc # v3.2.0
with:
version: v1.48.0
version: v1.49.0
4 changes: 2 additions & 2 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ type RateLimitedError struct {
RetryAfter time.Duration
}

func (e *RateLimitedError) Error() string {
func (e RateLimitedError) Error() string {
return fmt.Sprintf("slack rate limit exceeded, retry after %s", e.RetryAfter)
}

func (e *RateLimitedError) Retryable() bool {
func (e RateLimitedError) Retryable() bool {
return true
}

Expand Down
17 changes: 17 additions & 0 deletions misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slack

import (
"context"
"errors"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -104,3 +105,19 @@ func TestRetryable(t *testing.T) {
}
}
}

func TestCanUseErrorsAs(t *testing.T) {
ok := errors.As(RateLimitedError{}, &RateLimitedError{})
if !ok {
t.Errorf("cannot convert to RateLimitedError")
}
ok = errors.As(StatusCodeError{}, &StatusCodeError{})
if !ok {
t.Errorf("cannot convert to StatusCodeError")
}
ok = errors.As(SlackError{}, &SlackError{})
if !ok {
t.Errorf("cannot convert to SlackError")
}
// no panic means we're good
}

0 comments on commit 3a8b107

Please sign in to comment.