Codebase list golang-github-nlopes-slack / 277e4e8
Fixed error message handling on response Michael Stewart authored 8 years ago Norberto Lopes committed 8 years ago
3 changed file(s) with 22 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
156156
157157 type infoResponseFull struct {
158158 Info
159 SlackWSResponse
159 SlackWebResponse
160160 }
161161
162162 // GetBotByID returns a bot given a bot id
4848 info, conn, err = rtm.startRTMAndDial()
4949 if err == nil {
5050 break // connected
51 } else if sErr, ok := err.(*SlackWSError); ok {
51 } else if sErr, ok := err.(*SlackWebError); ok {
5252 if sErr.Error() == "invalid_auth" {
5353 rtm.IncomingEvents <- SlackEvent{"invalid_auth", &InvalidAuthEvent{}}
5454 return
00 package slack
11
2 import "encoding/json"
2 import (
3 "encoding/json"
4 "fmt"
5 )
36
47 // AckMessage is used for messages received in reply to other messages
58 type AckMessage struct {
912 SlackWSResponse
1013 }
1114
15 type SlackWebResponse struct {
16 Ok bool `json:"ok"`
17 Error *SlackWebError `json:"error"`
18 }
19
20 type SlackWebError string
21
22 func (s SlackWebError) Error() string {
23 return string(s)
24 }
25
1226 type SlackWSResponse struct {
1327 Ok bool `json:"ok"`
1428 Error *SlackWSError `json:"error"`
1529 }
1630
17 type SlackWSError string
31 type SlackWSError struct {
32 Code int
33 Msg string
34 }
1835
1936 func (s SlackWSError) Error() string {
20 return string(s)
37 return fmt.Sprintf("Code %d - %s", s.Code, s.Msg)
2138 }
2239
2340 type MessageEvent Message