-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
86 lines (68 loc) · 1.67 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
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
package vk_sdk
type apiError struct {
ErrorCode int `json:"error_code"`
ErrorSubcode *int `json:"error_subcode,omitempty"`
ErrorMsg string `json:"error_msg"`
ErrorText string `json:"error_text"`
ReqParams []RequestParam `json:"request_params"`
RedirURI *string `json:"redirect_uri,omitempty"`
ConfirmText *string `json:"confirmation_text,omitempty"`
// Captcha fields
CaptchaSID *string `json:"captcha_sid,omitempty"`
CaptchaImg *string `json:"captcha_img,omitempty"`
}
type RequestParam struct {
Key string `json:"key"`
Value string `json:"value"`
}
// Code returns error code.
func (e apiError) Code() int {
return e.ErrorCode
}
// Subcode returns error subcode.
func (e apiError) Subcode() *int {
return e.ErrorSubcode
}
// Msg returns error message.
func (e apiError) Msg() string {
return e.ErrorMsg
}
// Text returns error text.
func (e apiError) Text() string {
return e.ErrorText
}
func (e apiError) RequestParams() []RequestParam {
return e.ReqParams
}
func (e apiError) RedirectURI() *string {
return e.RedirURI
}
func (e apiError) ConfirmationText() *string {
return e.ConfirmText
}
func (e apiError) Is(code ErrorCode) bool {
return e.ErrorCode == int(code)
}
func (e apiError) Captcha() Captcha {
if e.CaptchaImg == nil && e.CaptchaSID == nil {
return nil
}
c := new(captcha)
if e.CaptchaSID != nil {
c.CaptchaSID = *e.CaptchaSID
}
if e.CaptchaImg != nil {
c.CaptchaImg = *e.CaptchaImg
}
return c
}
type captcha struct {
CaptchaSID string
CaptchaImg string
}
func (c captcha) SID() string {
return c.CaptchaSID
}
func (c captcha) Img() string {
return c.CaptchaImg
}