-
Notifications
You must be signed in to change notification settings - Fork 1
/
errorEvent.go
51 lines (41 loc) · 826 Bytes
/
errorEvent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package twitch
import (
"encoding/json"
"time"
)
type ErrorEventData struct {
err error
timestamp time.Time
}
func (l *ErrorEventData) GetType() EventType {
return EventError
}
func (l *ErrorEventData) GetData() interface{} {
return l
}
func (l *ErrorEventData) Error() string {
return l.err.Error()
}
func (l *ErrorEventData) RawError() error {
return l.err
}
func (l *ErrorEventData) Timestamp() time.Time {
return l.timestamp
}
func (l *ErrorEventData) AsJson() string {
s, _ := json.Marshal(l.AsMap())
return string(s)
}
func (l *ErrorEventData) AsMap() map[string]interface{} {
return map[string]interface{}{
"type": l.GetType(),
"err": l.err,
"data": l.GetData(),
}
}
func MakeErrorEvent(err error) ChatEvent {
return &ErrorEventData{
err: err,
timestamp: time.Now(),
}
}