samueljseay / recaptcha

A simple reCaptcha 2 library for Elixir applications.
MIT License
111 stars 56 forks source link

function nil.decode/1 is undefined #52

Closed tporto closed 4 years ago

tporto commented 4 years ago

`json = Application.get_env(:recaptcha, :json_library)

result =

  with {:ok, response} <-

         HTTPoison.post(url, body, @headers, timeout: timeout),

       {:ok, data} <- json.decode(response.body) do

    {:ok, data}

  end

case result do

  {:ok, data} -> {:ok, data}`
MyNameIsURL commented 4 years ago

@tporto The issue is Jason isn't set as the default (even though the Readme says otherwise). So you need to explicitly set your json_library in your config like so

 config :recaptcha,
    public_key: {:system, "RECAPTCHA_PUBLIC_KEY"},
    secret: {:system, "RECAPTCHA_PRIVATE_KEY"},
    json_library: Jason
sobolevn commented 4 years ago

Hm, it should be set as a default. That's a bug. And PRs are more than welcome! 👍

MyNameIsURL commented 4 years ago

@sobolevn PR https://github.com/samueljseay/recaptcha/pull/53 to set Jason as the json library in the even one isn't set in the config.