Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing the retry error to be emitted to be utilized by the caller #7

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/ex_pwned.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ defmodule ExPwned do
"""
def breached?(account) do
case Breaches.breachedaccount(account, truncateResponse: true) do
{:ok, result, _} when length(result) > 0 -> true
{:ok, %{msg: "no breach was found for given input"}, _} -> false
{:ok, result, _} when length(result) > 0 ->
true

{:ok, %{msg: "no breach was found for given input"}, _} ->
false

{:error, :rate, msg, retry_secs} ->
{:error, :rate, msg, retry_secs}
end
end

Expand Down
8 changes: 8 additions & 0 deletions lib/ex_pwned/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ defmodule ExPwned.Parser do
{:ok, %HTTPoison.Response{body: _, headers: _, status_code: 403}} ->
{:error, "no user agent has been specified in the request", 403}

{:ok, %HTTPoison.Response{body: _, headers: headers, status_code: 429}} ->
# headers to map
h = Enum.into(headers, %{})
retry = Map.fetch!(h, "Retry-After")
{retry_secs, ""} = Integer.parse(retry)
msg = "Rate limit exceeded. Retry-After seconds."
{:error, :rate, msg, retry_secs}

{:ok, %HTTPoison.Response{body: body, headers: _, status_code: status}} ->
{:error, body, status}

Expand Down