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

Expose StatusCodeError #1071

Merged
merged 2 commits into from Jun 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]
Maybe it is time to refactor error handling 🤔


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