Move authTest before creation of RTM

By moving authTest we'll be able to test the connection to
slack, and return a sensible error message when this fails.

Fixes #36
This commit is contained in:
erroneousboat 2016-10-21 14:05:36 +02:00
parent d2fb5c06d9
commit c2000265d1
3 changed files with 12 additions and 12 deletions

View File

@ -52,7 +52,7 @@ run: build
@ echo "+ $@"
@ ./bin/slack-term
install: build
install:
@ echo "+ $@"
@ go install .

View File

@ -32,7 +32,7 @@ var (
flgConfig string
flgUsage bool
VERSION = "v0.1.0-beta.2"
VERSION = "v0.1.0"
)
func init() {

View File

@ -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
@ -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
}