From 4198a89103dd5eac3b44fb2adc43b485aaf43e25 Mon Sep 17 00:00:00 2001 From: Samuel Seay Date: Mon, 5 Sep 2016 21:47:05 +1200 Subject: Add the case for when a recaptcha challenge fails but the request succeeds. --- README.md | 2 +- lib/recaptcha.ex | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a86f8f4..bc4a04d 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.1