Skip to content

Commit

Permalink
Merge pull request #1071 from photown/master
Browse files Browse the repository at this point in the history
Expose StatusCodeError
  • Loading branch information
kanata2 committed Jun 6, 2022
2 parents 1010af8 + d3e1f35 commit 06ab08c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
4 changes: 1 addition & 3 deletions misc.go
Expand Up @@ -18,8 +18,6 @@ import (
"strconv"
"strings"
"time"

"github.com/slack-go/slack/internal/misc"
)

// SlackResponse handles parsing out errors from the web api.
Expand Down Expand Up @@ -299,7 +297,7 @@ func checkStatusCode(resp *http.Response, d Debug) error {
// Slack seems to send an HTML body along with 5xx error codes. Don't parse it.
if resp.StatusCode != http.StatusOK {
logResponse(resp, d)
return misc.StatusCodeError{Code: resp.StatusCode, Status: resp.Status}
return StatusCodeError{Code: resp.StatusCode, Status: resp.Status}
}

return nil
Expand Down
6 changes: 2 additions & 4 deletions misc_test.go
Expand Up @@ -8,8 +8,6 @@ import (
"sync"
"testing"

"github.com/slack-go/slack/internal/misc"

"github.com/slack-go/slack/slackutilsx"
)

Expand Down Expand Up @@ -94,8 +92,8 @@ func TestParseResponseInvalidToken(t *testing.T) {
func TestRetryable(t *testing.T) {
for _, e := range []error{
&RateLimitedError{},
misc.StatusCodeError{Code: http.StatusInternalServerError},
misc.StatusCodeError{Code: http.StatusTooManyRequests},
StatusCodeError{Code: http.StatusInternalServerError},
StatusCodeError{Code: http.StatusTooManyRequests},
} {
r, ok := e.(slackutilsx.Retryable)
if !ok {
Expand Down
3 changes: 1 addition & 2 deletions socketmode/socket_mode_managed_conn.go
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/slack-go/slack"
"github.com/slack-go/slack/internal/backoff"
"github.com/slack-go/slack/internal/misc"
"github.com/slack-go/slack/internal/timex"
"github.com/slack-go/slack/slackevents"
)
Expand Down Expand Up @@ -213,7 +212,7 @@ func (smc *Client) connect(ctx context.Context, connectionCount int, additionalP
}

switch actual := err.(type) {
case misc.StatusCodeError:
case slack.StatusCodeError:
if actual.Code == http.StatusNotFound {
smc.Debugf("invalid auth when connecting with Socket Mode: %s", err)
smc.Events <- newEvent(EventTypeInvalidAuth, &slack.InvalidAuthEvent{})
Expand Down
2 changes: 1 addition & 1 deletion internal/misc/misc.go → status_code_error.go
@@ -1,4 +1,4 @@
package misc
package slack

import (
"fmt"
Expand Down
3 changes: 1 addition & 2 deletions websocket_managed_conn.go
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/slack-go/slack/internal/backoff"
"github.com/slack-go/slack/internal/errorsx"
"github.com/slack-go/slack/internal/misc"
"github.com/slack-go/slack/internal/timex"
)

Expand Down Expand Up @@ -127,7 +126,7 @@ func (rtm *RTM) connect(connectionCount int, useRTMStart bool) (*Info, *websocke
}

switch actual := err.(type) {
case misc.StatusCodeError:
case StatusCodeError:
if actual.Code == http.StatusNotFound {
rtm.Debugf("invalid auth when connecting with RTM: %s", err)
rtm.IncomingEvents <- RTMEvent{"invalid_auth", &InvalidAuthEvent{}}
Expand Down

0 comments on commit 06ab08c

Please sign in to comment.