Skip to content

Instantly share code, notes, and snippets.

@iantbutler01
Last active February 5, 2020 06:53
Show Gist options
  • Save iantbutler01/f50cde9bed137a9ac5827544ec2c7a65 to your computer and use it in GitHub Desktop.
Save iantbutler01/f50cde9bed137a9ac5827544ec2c7a65 to your computer and use it in GitHub Desktop.
defp request_page(url) do
case HTTPoison.get(url) do
{:error, res} ->
{:error, res.reason}
{:ok, res} ->
case res do
%HTTPoison.Response{status_code: 404} -> {:error, 404}
%HTTPoison.Response{status_code: 401} -> {:error, 401}
%HTTPoison.Response{status_code: 403} -> {:error, 403}
%HTTPoison.Response{status_code: 200, body: body} -> {:ok, body}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment