-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
92 lines (81 loc) · 2.34 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
package huwlte
import (
"errors"
"fmt"
)
type ErrorCode int
// String returns the string representation of the error code.
func (ec ErrorCode) String() string {
switch ec {
case ErrorCodeInternal:
return "internal"
case ErrorCodeNotSupported:
return "not supported"
case ErrorCodeNoRights:
return "no rights"
case ErrorCodeBusy:
return "busy"
case ErrorCodeCSRF:
return "csrf"
case ErrorCodeWrongToken:
return "wrong token"
case ErrorCodeWrongSessionToken:
return "wrong session token"
case ErrorCodeUsernameWrong:
return "wrong username"
case ErrorCodePasswordWrong:
return "wrong password"
case ErrorCodeAlreadyLogin:
return "already login"
case ErrorCodeUsernamePwdWrong:
return "username or password wrong"
case ErrorCodeUsernamePwdOrerrun:
return "username or password orerrun"
case ErrorCodeUsernamePwdModify:
return "username or password modify"
case ErrorCodeSetNetModeAndBandWhenDialupFailed:
return "set net mode and band when dialup failed"
case ErrorCodeSetNetModeAndBandFailed:
return "set net mode and band failed"
default:
return fmt.Sprintf("unknown(%d)", ec)
}
}
const (
ErrorCodeInternal ErrorCode = 100001
ErrorCodeNotSupported ErrorCode = 100002
ErrorCodeNoRights ErrorCode = 100003
ErrorCodeBusy ErrorCode = 100004
ErrorCodeCSRF ErrorCode = 125002
ErrorCodeWrongToken ErrorCode = 125001
// ErrorCodeWrongSession ErrorCode = 125002
ErrorCodeWrongSessionToken ErrorCode = 125003
ErrorCodeUsernameWrong ErrorCode = 108001
ErrorCodePasswordWrong ErrorCode = 108002
ErrorCodeAlreadyLogin ErrorCode = 108003
ErrorCodeUsernamePwdWrong ErrorCode = 108006
ErrorCodeUsernamePwdOrerrun ErrorCode = 108007
ErrorCodeUsernamePwdModify ErrorCode = 115002
ErrorCodeSetNetModeAndBandWhenDialupFailed ErrorCode = 112001
ErrorCodeSetNetModeAndBandFailed ErrorCode = 112003
)
type Error struct {
Code ErrorCode
Message string
}
func newError(ec int, message string) *Error {
return &Error{
Code: ErrorCode(ec),
Message: message,
}
}
func (err *Error) Error() string {
if err.Message == "" {
return fmt.Sprintf("%d: %s", err.Code, err.Code.String())
}
return fmt.Sprintf("%d: %s (%s)", err.Code, err.Code.String(), err.Message)
}
func IsError(err error, code ErrorCode) bool {
var herr *Error
return errors.As(err, &herr) && herr.Code == code
}