Skip to content

Commit

Permalink
Handle ratelimit and invalid auth RTM errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 30, 2024
1 parent 281dc21 commit 1180a3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
ErrAlreadyDisconnected = errorsx.String("Invalid call to Disconnect - Slack API is already disconnected")
ErrRTMDisconnected = errorsx.String("disconnect received while trying to connect")
ErrRTMGoodbye = errorsx.String("goodbye detected")
ErrRTMInvalidAuth = errorsx.String("invalid authentication")
ErrRTMDeadman = errorsx.String("deadman switch triggered")
ErrParametersMissing = errorsx.String("received empty parameters")
ErrBlockIDNotUnique = errorsx.String("Block ID needs to be unique")
Expand Down
13 changes: 10 additions & 3 deletions websocket_managed_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,18 @@ func (rtm *RTM) handleError(event json.RawMessage) {
return
}

if p.Error.Code == 1 {
rtm.IncomingEvents <- RTMEvent{"error", &p}
switch p.Error.Code {
case 1:
rtm.reconnectURL = ""
case 17:
rtm.Client.log.Println("Ratelimited event in RTM, sleeping")
// TODO make this less hacky?
time.Sleep(1 * time.Minute)
case 401:
_ = rtm.killConnection(true, ErrRTMInvalidAuth)
rtm.IncomingEvents <- RTMEvent{"invalid_auth", &InvalidAuthEvent{}}
}

rtm.IncomingEvents <- RTMEvent{"error", &p}
}

func (rtm *RTM) handleReconnectURL(event json.RawMessage) {
Expand Down

0 comments on commit 1180a3f

Please sign in to comment.