Fix error handling
Errors now also get passed to the user as *slack.SlackWSError
Norberto Lopes
9 years ago
42 | 42 |
case slack.LatencyReport:
|
43 | 43 |
a := msg.Data.(slack.LatencyReport)
|
44 | 44 |
fmt.Printf("Current latency: %v\n", a.Value)
|
|
45 |
case *slack.SlackWSError:
|
|
46 |
error := msg.Data.(*slack.SlackWSError)
|
|
47 |
fmt.Printf("Error: %d - %s\n", error.Code, error.Msg)
|
45 | 48 |
default:
|
46 | 49 |
fmt.Printf("Unexpected: %v\n", msg.Data)
|
47 | 50 |
}
|
59 | 59 |
ReplyTo int `json:"reply_to"`
|
60 | 60 |
}
|
61 | 61 |
|
62 | |
// AckMessage is used for messages received in reply to other messages
|
63 | |
type AckMessage struct {
|
64 | |
ReplyTo int `json:"reply_to"`
|
65 | |
Timestamp string `json:"ts"`
|
66 | |
Text string `json:"text"`
|
67 | |
SlackResponse
|
68 | |
}
|
69 | |
|
70 | 62 |
// NewOutGoingMessage prepares an OutgoingMessage that the user can use to send a message
|
71 | 63 |
func (api *SlackWS) NewOutgoingMessage(text string, channel string) *OutgoingMessage {
|
72 | 64 |
api.mutex.Lock()
|
21 | 21 |
mutex sync.Mutex
|
22 | 22 |
pings map[int]time.Time
|
23 | 23 |
Slack
|
|
24 |
}
|
|
25 |
|
|
26 |
// AckMessage is used for messages received in reply to other messages
|
|
27 |
type AckMessage struct {
|
|
28 |
ReplyTo int `json:"reply_to"`
|
|
29 |
Timestamp string `json:"ts"`
|
|
30 |
Text string `json:"text"`
|
|
31 |
SlackWSResponse
|
24 | 32 |
}
|
25 | 33 |
|
26 | 34 |
type SlackWSResponse struct {
|
|
190 | 198 |
return
|
191 | 199 |
}
|
192 | 200 |
|
193 | |
// TODO: errors end up in this bucket. They shouldn't.
|
194 | |
log.Printf("Got error(?): %s", event)
|
|
201 |
// Send the error to the user
|
|
202 |
ch <- SlackEvent{Data: ack.Error}
|
195 | 203 |
case "hello":
|
196 | 204 |
ch <- SlackEvent{Data: HelloEvent{}}
|
197 | 205 |
case "pong":
|