Fixed error message handling on response
Michael Stewart authored 8 years ago
Norberto Lopes committed 8 years ago
48 | 48 |
info, conn, err = rtm.startRTMAndDial()
|
49 | 49 |
if err == nil {
|
50 | 50 |
break // connected
|
51 | |
} else if sErr, ok := err.(*SlackWSError); ok {
|
|
51 |
} else if sErr, ok := err.(*SlackWebError); ok {
|
52 | 52 |
if sErr.Error() == "invalid_auth" {
|
53 | 53 |
rtm.IncomingEvents <- SlackEvent{"invalid_auth", &InvalidAuthEvent{}}
|
54 | 54 |
return
|
0 | 0 |
package slack
|
1 | 1 |
|
2 | |
import "encoding/json"
|
|
2 |
import (
|
|
3 |
"encoding/json"
|
|
4 |
"fmt"
|
|
5 |
)
|
3 | 6 |
|
4 | 7 |
// AckMessage is used for messages received in reply to other messages
|
5 | 8 |
type AckMessage struct {
|
|
9 | 12 |
SlackWSResponse
|
10 | 13 |
}
|
11 | 14 |
|
|
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 |
|
12 | 26 |
type SlackWSResponse struct {
|
13 | 27 |
Ok bool `json:"ok"`
|
14 | 28 |
Error *SlackWSError `json:"error"`
|
15 | 29 |
}
|
16 | 30 |
|
17 | |
type SlackWSError string
|
|
31 |
type SlackWSError struct {
|
|
32 |
Code int
|
|
33 |
Msg string
|
|
34 |
}
|
18 | 35 |
|
19 | 36 |
func (s SlackWSError) Error() string {
|
20 | |
return string(s)
|
|
37 |
return fmt.Sprintf("Code %d - %s", s.Code, s.Msg)
|
21 | 38 |
}
|
22 | 39 |
|
23 | 40 |
type MessageEvent Message
|