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:
parent
10e4469bae
commit
7a4dbd45b5
2
Makefile
2
Makefile
@ -52,7 +52,7 @@ run: build
|
||||
@ echo "+ $@"
|
||||
@ ./bin/slack-term
|
||||
|
||||
install: build
|
||||
install:
|
||||
@ echo "+ $@"
|
||||
@ go install .
|
||||
|
||||
|
2
main.go
2
main.go
@ -32,7 +32,7 @@ var (
|
||||
flgConfig string
|
||||
flgUsage bool
|
||||
|
||||
VERSION = "v0.1.0-beta.2"
|
||||
VERSION = "v0.1.0"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user