-
Notifications
You must be signed in to change notification settings - Fork 7
/
errors.go
119 lines (101 loc) · 3.4 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package vkapi
import (
"errors"
"fmt"
"strings"
)
type ServerError int
const (
// Full description at https://vk.com/dev/errors
ErrZero ServerError = 0
ErrUnknown ServerError = 1
ErrApplicationDisabled ServerError = 2
ErrUnknownMethod ServerError = 3
ErrInvalidSignature ServerError = 4
ErrAuthFailed ServerError = 5
ErrTooManyRequests ServerError = 6
ErrInsufficientPermissions ServerError = 7
ErrInvalidRequest ServerError = 8
ErrTooManyOneTypeRequests ServerError = 9
ErrInternalServerError ServerError = 10
ErrAppInTestMode ServerError = 11
ErrCaptchaNeeded ServerError = 14
ErrNotAllowed ServerError = 15
ErrHttpsOnly ServerError = 16
ErrNeedValidation ServerError = 17
ErrUserDeletedOrBlocked ServerError = 18
ErrStandaloneOnly ServerError = 20
ErrStandaloneOpenAPIOnly ServerError = 21
ErrMethodDisabled ServerError = 23
ErrNeedConfirmation ServerError = 24
ErrCommunityKeyInvalid ServerError = 27
ErrApplicationKeyInvalid ServerError = 28
ErrOneOfParametersInvalid ServerError = 100
ErrInvalidAPIID ServerError = 101
ErrInvalidAUserID ServerError = 113
ErrInvalidTimestamp ServerError = 150
ErrAlbumAccessProhibited ServerError = 200
ErrAudioAccessProhibited ServerError = 201
ErrGroupAccessProhibited ServerError = 203
ErrAlbumOverflow ServerError = 300
ErrEnableVoiceApplication ServerError = 500
ErrInsufficientPermissionsAd ServerError = 600
ErrInternalServerErrorAd ServerError = 603
ErrInBlackList ServerError = 900
ErrNotAllowedToSendFirst ServerError = 901
ErrPrivacy ServerError = 902
ErrBadResponseCode ServerError = -1
ErrBadCode ServerError = -666
)
type Errors []ExecuteError
func (e Errors) Error() string {
var s []string
for _, v := range e {
s = append(s, v.Error())
}
return fmt.Sprintln("Execute errors:", strings.Join(s, ", "))
}
type RequestParam struct {
Key string `json:"key"`
Value string `json:"value"`
}
type ExecuteError struct {
Method string `json:"method"`
Code ServerError `json:"error_code"`
Message string `json:"error_msg"`
}
// Error contains standard errors.
type Error struct {
Code ServerError `json:"error_code,omitempty"`
Message string `json:"error_msg,omitempty"`
Params *[]RequestParam `json:"request_params,omitempty"`
CaptchaSid string `json:"captcha_sid,omitempty"`
CaptchaImg string `json:"captcha_img,omitempty"`
Request Request `json:"-"`
}
func (e Error) ToError() error {
return errors.New(fmt.Sprintf("%s (%d)", e.Message, e.Code))
}
// NewError makes *Error from our ServerError and description.
func NewError(code ServerError, description string) (err *Error) {
err = new(Error)
err.Code = code
err.Message = description
return
}
// setRequest sets Request
func (e *Error) setRequest(r Request) {
e.Request = r
}
func (e Error) Error() string {
return fmt.Sprintf("%s (%d)", e.Message, e.Code)
}
func (e ExecuteError) Error() string {
return fmt.Sprintf("%s: %s (%d)", e.Method, e.Message, e.Code)
}
func (s ServerError) String() string {
return fmt.Sprintf("%d", s)
}
func (s ServerError) Error() string {
return s.String()
}