-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
66 lines (55 loc) · 1.94 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
package recaptcha
import (
"fmt"
"strings"
"time"
)
// VerificationError is returned from Verify when the response's "success"
// field is false or the "error-codes" field is non-empty. This is the only
// error the can be returned from Verify if no additional verification criteria
// are provided.
type VerificationError struct {
ErrorCodes []string
}
func (e *VerificationError) Error() string {
if len(e.ErrorCodes) > 0 {
return fmt.Sprintf("invalid reCAPTCHA: %s", strings.Join(e.ErrorCodes, ","))
}
return "invalid reCAPTCHA (success: false)"
}
// InvalidHostnameError is returned from Verify if the Hostname criterion is
// provided and the response's "hostname" field does not correspond to the
// expected hostname.
type InvalidHostnameError struct {
Hostname string
}
func (e *InvalidHostnameError) Error() string {
return fmt.Sprintf("invalid reCAPTCHA: invalid hostname: %s", e.Hostname)
}
// InvalidActionError is returned from Verify if the Action criterion is
// provided and the response's "action" field does not correspond to the
// expected action.
type InvalidActionError struct {
Action string
}
func (e *InvalidActionError) Error() string {
return fmt.Sprintf("invalid reCAPTCHA: invalid action: %s", e.Action)
}
// InvalidScoreError is returned from Verify if the Score criterion is provided
// and the response's "score" field is below the minimum threshold.
type InvalidScoreError struct {
Score float64
}
func (e *InvalidScoreError) Error() string {
return fmt.Sprintf("invalid reCAPTCHA: invalid score: %f", e.Score)
}
// InvalidChallengeTsError is returned from Verify if the ChallengeTs criterion
// is provided and the response's "challenge_ts" field falls outside the valid
// window.
type InvalidChallengeTsError struct {
ChallengeTs time.Time
Diff time.Duration
}
func (e *InvalidChallengeTsError) Error() string {
return fmt.Sprintf("invalid reCAPTCHA: invalid challenge timestamp: %s (%s old)", e.ChallengeTs, e.Diff)
}