Skip to content

Commit 4198a89

Browse files
author
Samuel Seay
committed
Add the case for when a recaptcha challenge fails but the request succeeds.
1 parent a8da396 commit 4198a89

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Recaptcha provides the `verify/2` method. Below is an example using a Phoenix co
8888

8989
`{:ok, %Recaptcha.Response{challenge_ts: timestamp, hostname: host}}` -> The captcha is valid, see the [documentation](https://developers.google.com/recaptcha/docs/verify#api-response) for more details.
9090

91-
`{:error, errors}` -> `errors` contains atomised versions of the errors returned by the API, See the [error documentation](https://developers.google.com/recaptcha/docs/verify#error-code-reference) for more details. Errors caused by timeouts in HTTPoison or Poison encoding are also returned as atoms.
91+
`{:error, errors}` -> `errors` contains atomised versions of the errors returned by the API, See the [error documentation](https://developers.google.com/recaptcha/docs/verify#error-code-reference) for more details. Errors caused by timeouts in HTTPoison or Poison encoding are also returned as atoms. If the recaptcha request succeeds but the challenge is failed, a ``:challenge_failed` error is returned.
9292

9393
`verify` method also accepts a keyword list as the third parameter with the following options:
9494

lib/recaptcha.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ defmodule Recaptcha do
4141
{:error, Enum.map(errors, fn(error) -> atomise_api_error(error) end)}
4242
{:ok, %{"success" => true, "challenge_ts" => timestamp, "hostname" => host}} ->
4343
{:ok, %Recaptcha.Response{challenge_ts: timestamp, hostname: host}}
44+
{:ok, %{"success" => false, "challenge_ts" => timestamp, "hostname" => host}} ->
45+
{:error, [:challenge_failed]}
4446
end
4547
end
4648

0 commit comments

Comments
 (0)