Skip to content

Commit

Permalink
Move authTest before creation of RTM
Browse files Browse the repository at this point in the history
By moving authTest we'll be able to test the connection to
slack, and return a sensible error message when this fails.

Fixes #36
  • Loading branch information
jpbruinsslot committed Oct 21, 2016
1 parent d2fb5c0 commit c200026
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ run: build
@ echo "+ $@"
@ ./bin/slack-term

install: build
install:
@ echo "+ $@"
@ go install .

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
flgConfig string
flgUsage bool

VERSION = "v0.1.0-beta.2"
VERSION = "v0.1.0"
)

func init() {
Expand Down
20 changes: 10 additions & 10 deletions service/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ func NewSlackService(token string) *SlackService {
UserCache: make(map[string]string),
}

svc.RTM = svc.Client.NewRTM()
// Get user associated with token, mainly
// used to identify user when new messages
// arrives
authTest, err := svc.Client.AuthTest()
if err != nil {
log.Fatal("ERROR: not able to authorize client, check your connection and/or slack-token")
}
svc.CurrentUserID = authTest.UserID

// Create RTM
svc.RTM = svc.Client.NewRTM()
go svc.RTM.ManageConnection()

// Creation of user cache this speeds up
Expand All @@ -45,15 +54,6 @@ func NewSlackService(token string) *SlackService {
}
}

// Get user associated with token, mainly
// used to identify user when new messages
// arrives
authTest, err := svc.Client.AuthTest()
if err != nil {
log.Fatal("Client.AuthTest() failed")
}
svc.CurrentUserID = authTest.UserID

return svc
}

Expand Down

0 comments on commit c200026

Please sign in to comment.