You are here

function recaptcha_v3_error_by_code in reCAPTCHA v3 8

Return error by code from response.

Error code reference, https://developers.google.com/recaptcha/docs/verify.

Parameters

string $code: The error code in google api response.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup Return an array of error code description.

1 call to recaptcha_v3_error_by_code()
recaptcha_v3_validate in ./recaptcha_v3.module
CAPTCHA Callback; Validates the reCAPTCHA v3 code.

File

./recaptcha_v3.module, line 336
Contains recaptcha_v3.module.

Code

function recaptcha_v3_error_by_code($code) {
  $error_codes =& drupal_static(__FUNCTION__);
  if (!isset($error_codes)) {
    $error_codes = [
      'timeout-or-duplicate' => t('The response is no longer valid: either is too old or has been used previously.'),
      'bad-request' => t('The request is invalid or malformed.'),
      'missing-input-secret' => t('The secret parameter is missing.'),
      'invalid-input-secret' => t('The secret parameter is invalid or malformed.'),
      'action-mismatch' => t('Expected action did not match.'),
      'apk_package_name-mismatch' => t('Expected APK package name did not match.'),
      'bad-response' => t('Did not receive a 200 from the service.'),
      'challenge-timeout' => t('Challenge timeout.'),
      'connection-failed' => t('Could not connect to service.'),
      'invalid-input-response' => t('The response parameter is invalid or malformed.'),
      'missing-input-response' => t('The response parameter is missing.'),
      'hostname-mismatch' => t('Expected hostname did not match.'),
      'invalid-json' => t('The json response is invalid or malformed.'),
      'score-threshold-not-met' => t('Score threshold not met.'),
      'unknown-error' => t('Not a success, but no error codes received!'),
    ];
  }
  return $error_codes[$code] ?? $error_codes['unknown-error'];
}