You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.go 1.7KB

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