1// Copyright 2023 The Gitea Authors. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4package hcaptcha
5
6const (
7 ErrMissingInputSecret ErrorCode = "missing-input-secret"
8 ErrInvalidInputSecret ErrorCode = "invalid-input-secret"
9 ErrMissingInputResponse ErrorCode = "missing-input-response"
10 ErrInvalidInputResponse ErrorCode = "invalid-input-response"
11 ErrBadRequest ErrorCode = "bad-request"
12 ErrInvalidOrAlreadySeenResponse ErrorCode = "invalid-or-already-seen-response"
13 ErrNotUsingDummyPasscode ErrorCode = "not-using-dummy-passcode"
14 ErrSitekeySecretMismatch ErrorCode = "sitekey-secret-mismatch"
15)
16
17// ErrorCode is any possible error from hCaptcha
18type ErrorCode string
19
20// String fulfills the Stringer interface
21func (err ErrorCode) String() string {
22 switch err {
23 case ErrMissingInputSecret:
24 return "Your secret key is missing."
25 case ErrInvalidInputSecret:
26 return "Your secret key is invalid or malformed."
27 case ErrMissingInputResponse:
28 return "The response parameter (verification token) is missing."
29 case ErrInvalidInputResponse:
30 return "The response parameter (verification token) is invalid or malformed."
31 case ErrBadRequest:
32 return "The request is invalid or malformed."
33 case ErrInvalidOrAlreadySeenResponse:
34 return "The response parameter has already been checked, or has another issue."
35 case ErrNotUsingDummyPasscode:
36 return "You have used a testing sitekey but have not used its matching secret."
37 case ErrSitekeySecretMismatch:
38 return "The sitekey is not registered with the provided secret."
39 default:
40 return ""
41 }
42}
43
44// Error fulfills the error interface
45func (err ErrorCode) Error() string {
46 return err.String()
47}