This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
forked from Rhymen/go-whatsapp
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy patherrors.go
102 lines (86 loc) · 4.12 KB
/
errors.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package whatsapp
import (
"encoding/json"
"errors"
"fmt"
)
var (
ErrAlreadyConnected = errors.New("already connected")
ErrAlreadyLoggedIn = errors.New("already logged in")
ErrSessionExists = errors.New("a session with keys is already present")
ErrInvalidSession = errors.New("invalid session")
ErrLoginInProgress = errors.New("login or restore already running")
ErrNotConnected = errors.New("not connected")
ErrNotLoggedIn = errors.New("not logged in")
ErrInvalidWsData = errors.New("received invalid data")
ErrInvalidWsState = errors.New("can't handle binary data when not logged in")
ErrConnectionTimeout = errors.New("connection timed out")
ErrMissingMessageTag = errors.New("no messageTag specified or to short")
ErrInvalidHmac = errors.New("invalid hmac")
ErrInvalidServerResponse = errors.New("invalid response received from server")
ErrServerRespondedWith404 = errors.New("server responded with status 404")
ErrMediaDownloadFailedWith404 = errors.New("download failed with status code 404")
ErrMediaDownloadFailedWith410 = errors.New("download failed with status code 410")
ErrLoginTimedOut = errors.New("login timed out")
ErrQueryTimeout = errors.New("query timed out")
ErrRestoreSessionInitTimeout = errors.New("restore session init timed out")
ErrLoginCancelled = errors.New("login cancelled")
ErrAbortLogin = errors.New("abort login")
ErrPingFalse = errors.New("ping returned false")
ErrWebsocketKeepaliveFailed = errors.New("websocket keepalive failed")
ErrUnexpectedLoginMsgType = errors.New("unexpected message type after login")
ErrMultiDeviceNotSupported = errors.New("phone has multi-device enabled, which is not yet supported")
ErrBadRequest = errors.New("400 (bad request)")
ErrUnpaired = errors.New("401 (unpaired from phone)")
ErrAccessDenied = errors.New("403 (access denied)")
ErrLoggedIn = errors.New("405 (already logged in)")
ErrReplaced = errors.New("409 (logged in from another location)")
ErrNoURLPresent = errors.New("no url present")
ErrFileLengthMismatch = errors.New("file length does not match")
ErrInvalidHashLength = errors.New("hash too short")
ErrTooShortFile = errors.New("file too short")
ErrInvalidMediaHMAC = errors.New("invalid media hmac")
ErrCantGetInviteLink = errors.New("you don't have the permission to view the invite link")
ErrJoinUnauthorized = errors.New("you're not allowed to join that group")
ErrInvalidWebsocket = errors.New("invalid websocket")
ErrWebsocketClosedBeforeLogin = errors.New("connection closed before login finished")
ErrMessageTypeNotImplemented = errors.New("message type not implemented")
ErrOptionsNotProvided = errors.New("new conn options not provided")
)
type ErrConnectionFailed struct {
Err error
}
func (e *ErrConnectionFailed) Error() string {
return fmt.Sprintf("connection to WhatsApp servers failed: %v", e.Err)
}
type ErrConnectionClosed struct {
Code int
Text string
}
func (e *ErrConnectionClosed) Error() string {
return fmt.Sprintf("server closed connection,code: %d,text: %s", e.Code, e.Text)
}
type StatusResponseFields struct {
// The response status code. This is always expected to be present.
Status int `json:"status"`
// Some error messages include a "tos" value. If it's higher than 0, it
// might mean the user has been banned for breaking the terms of service.
TermsOfService int `json:"tos,omitempty"`
// This is a timestamp that's at least present in message send responses.
Timestamp int64 `json:"t,omitempty"`
}
type StatusResponse struct {
StatusResponseFields
RequestType string `json:"-"`
Extra map[string]interface{} `json:"-"`
}
func (sr *StatusResponse) UnmarshalJSON(data []byte) error {
err := json.Unmarshal(data, &sr.Extra)
if err != nil {
return err
}
return json.Unmarshal(data, &sr.StatusResponseFields)
}
func (sr StatusResponse) Error() string {
return fmt.Sprintf("%s responded with %d", sr.RequestType, sr.Status)
}