diff --git a/context/context.go b/context/context.go index 7ea6e7a..90c83ba 100644 --- a/context/context.go +++ b/context/context.go @@ -34,7 +34,10 @@ func CreateAppContext(flgConfig string) (*AppContext, error) { } // Create Service - svc := service.NewSlackService(config.SlackToken) + svc, err := service.NewSlackService(config.SlackToken) + if err != nil { + return nil, err + } // Create ChatView view := views.CreateChatView(svc) diff --git a/service/slack.go b/service/slack.go index efa1d87..a48633f 100644 --- a/service/slack.go +++ b/service/slack.go @@ -1,6 +1,7 @@ package service import ( + "errors" "fmt" "log" "regexp" @@ -38,7 +39,7 @@ type Channel struct { // NewSlackService is the constructor for the SlackService and will initialize // the RTM and a Client -func NewSlackService(token string) *SlackService { +func NewSlackService(token string) (*SlackService, error) { svc := &SlackService{ Client: slack.New(token), UserCache: make(map[string]string), @@ -49,7 +50,7 @@ func NewSlackService(token string) *SlackService { // arrives authTest, err := svc.Client.AuthTest() 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 @@ -67,7 +68,7 @@ func NewSlackService(token string) *SlackService { } } - return svc + return svc, nil } // GetChannels will retrieve all available channels, groups, and im channels.