diff options
author | Samuel Seay <sam@manuka.co> | 2016-09-05 21:47:05 +1200 |
---|---|---|
committer | Samuel Seay <sam@manuka.co> | 2016-09-05 21:47:05 +1200 |
commit | 4198a89103dd5eac3b44fb2adc43b485aaf43e25 (patch) | |
tree | ab4521b420150a71ea4e7b303cb23e7157028e9f | |
parent | a8da396dfc04e31854272d462e910a6c0ac35910 (diff) | |
download | recaptcha-4198a89103dd5eac3b44fb2adc43b485aaf43e25.tar.gz recaptcha-4198a89103dd5eac3b44fb2adc43b485aaf43e25.tar.xz |
Add the case for when a recaptcha challenge fails but the request succeeds.2.0
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib/recaptcha.ex | 2 |
2 files changed, 3 insertions, 1 deletions
@@ -88,7 +88,7 @@ Recaptcha provides the `verify/2` method. Below is an example using a Phoenix co `{: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. -`{: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. +`{: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. `verify` method also accepts a keyword list as the third parameter with the following options: diff --git a/lib/recaptcha.ex b/lib/recaptcha.ex index 9e6be0f..30a5bd8 100644 --- a/lib/recaptcha.ex +++ b/lib/recaptcha.ex @@ -41,6 +41,8 @@ defmodule Recaptcha do {:error, Enum.map(errors, fn(error) -> atomise_api_error(error) end)} {:ok, %{"success" => true, "challenge_ts" => timestamp, "hostname" => host}} -> {:ok, %Recaptcha.Response{challenge_ts: timestamp, hostname: host}} + {:ok, %{"success" => false, "challenge_ts" => timestamp, "hostname" => host}} -> + {:error, [:challenge_failed]} end end |