From e004b65263d0409e162315cb1cc073c2f7bef5da Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 30 Jun 2019 21:31:24 -0400 Subject: [PATCH] Additional HTTP error handling in get_article_content --- lib/frenzy/update_feeds.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/frenzy/update_feeds.ex b/lib/frenzy/update_feeds.ex index 382680b..f68bfeb 100644 --- a/lib/frenzy/update_feeds.ex +++ b/lib/frenzy/update_feeds.ex @@ -199,7 +199,8 @@ defmodule Frenzy.UpdateFeeds do {:ok, %HTTPoison.Response{status_code: 404}} -> {:err, "404 not found"} - {:ok, %HTTPoison.Response{status_code: 301, headers: headers}} -> + {:ok, %HTTPoison.Response{status_code: status_code, headers: headers}} + when status_code == 301 or status_code == 302 -> {"Location", new_url} = Enum.find(headers, fn {name, _value} -> name == "Location" @@ -208,6 +209,9 @@ defmodule Frenzy.UpdateFeeds do Logger.debug("Got 301 redirect from #{url} to #{new_url}") get_article_content(new_url) + {:ok, %HTTPoison.Response{status_code: 403}} -> + {:err, "403 Forbidden"} + {:error, %HTTPoison.Error{reason: reason}} -> {:err, reason} end