Fix terminal state when connection fails

Fixes #66
This commit is contained in:
erroneousboat 2017-12-01 11:30:43 +01:00
parent e10fef8b9d
commit cf7efb6cc9
2 changed files with 8 additions and 4 deletions

View File

@ -34,7 +34,10 @@ func CreateAppContext(flgConfig string) (*AppContext, error) {
} }
// Create Service // Create Service
svc := service.NewSlackService(config.SlackToken) svc, err := service.NewSlackService(config.SlackToken)
if err != nil {
return nil, err
}
// Create ChatView // Create ChatView
view := views.CreateChatView(svc) view := views.CreateChatView(svc)

View File

@ -1,6 +1,7 @@
package service package service
import ( import (
"errors"
"fmt" "fmt"
"log" "log"
"regexp" "regexp"
@ -38,7 +39,7 @@ type Channel struct {
// NewSlackService is the constructor for the SlackService and will initialize // NewSlackService is the constructor for the SlackService and will initialize
// the RTM and a Client // the RTM and a Client
func NewSlackService(token string) *SlackService { func NewSlackService(token string) (*SlackService, error) {
svc := &SlackService{ svc := &SlackService{
Client: slack.New(token), Client: slack.New(token),
UserCache: make(map[string]string), UserCache: make(map[string]string),
@ -49,7 +50,7 @@ func NewSlackService(token string) *SlackService {
// arrives // arrives
authTest, err := svc.Client.AuthTest() authTest, err := svc.Client.AuthTest()
if err != nil { if err != nil {
log.Fatal("ERROR: not able to authorize client, check your connection and/or slack-token") return nil, errors.New("not able to authorize client, check your connection and or slack-token")
} }
svc.CurrentUserID = authTest.UserID svc.CurrentUserID = authTest.UserID
@ -67,7 +68,7 @@ func NewSlackService(token string) *SlackService {
} }
} }
return svc return svc, nil
} }
// GetChannels will retrieve all available channels, groups, and im channels. // GetChannels will retrieve all available channels, groups, and im channels.