-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
56 lines (45 loc) · 1.25 KB
/
error.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
52
53
54
55
56
package five9
import (
"encoding/json"
"errors"
"fmt"
)
type five9Error struct {
Five9ExceptionDetail five9ExceptionDetail `json:"five9ExceptionDetail"`
}
type five9ExceptionDetail struct {
Timestamp uint `json:"timestamp"`
ErrorCode int `json:"errorCode"`
Message string `json:"message"`
Context errorContext `json:"context"`
}
type errorContext struct {
ContextCode string `json:"contextCode"`
ObjectID string `json:"objectId"`
}
type Error struct {
StatusCode int `json:"status_code"`
Body []byte `json:"body"`
Message string `json:"message"`
}
func (err *Error) Error() string {
if err.Message == "" {
return fmt.Sprintf("Five9 REST API Error, Status Code: %d", err.StatusCode)
}
return err.Message
}
func (err *Error) UnmarshalJSON(b []byte) error {
target := five9Error{}
if targetErr := json.Unmarshal(b, &target); targetErr == nil {
if target.Five9ExceptionDetail.Message != "" {
err.Message = target.Five9ExceptionDetail.Message
return nil
}
}
return nil
}
var (
ErrUnknownUserID error = errors.New("unknown userID provided")
ErrWebSocketCacheNotReady error = errors.New("webSocket cache is not ready")
ErrWebSocketCacheStale error = errors.New("webSocket cache is stale")
)