Compare commits
1 Commits
12a426254d
...
7a962b2c57
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 7a962b2c57 |
|
@ -74,6 +74,17 @@ defmodule Frenzy.UpdateFeeds do
|
||||||
{:ok, %HTTPoison.Response{status_code: 404}} ->
|
{:ok, %HTTPoison.Response{status_code: 404}} ->
|
||||||
Logger.warn("RSS feed #{feed.feed_url} not found")
|
Logger.warn("RSS feed #{feed.feed_url} not found")
|
||||||
|
|
||||||
|
{:ok, %HTTPoison.Response{status_code: status_code}} when status_code in [301, 302] ->
|
||||||
|
{"Location", new_url} =
|
||||||
|
Enum.find(headers, fn {name, _value} ->
|
||||||
|
name == "Location"
|
||||||
|
end)
|
||||||
|
|
||||||
|
Logger.debug("Got 301 redirect from #{url} to #{new_url}, updating feed URL")
|
||||||
|
changeset = Feed.changeset(feed, %{feed_url: new_url})
|
||||||
|
{:ok, feed} = Repo.insert(changeset)
|
||||||
|
update_feed(feed)
|
||||||
|
|
||||||
{:error, %HTTPoison.Error{reason: reason}} ->
|
{:error, %HTTPoison.Error{reason: reason}} ->
|
||||||
Logger.error("Couldn't load RSS feed: #{reason}")
|
Logger.error("Couldn't load RSS feed: #{reason}")
|
||||||
end
|
end
|
||||||
|
@ -200,7 +211,7 @@ defmodule Frenzy.UpdateFeeds do
|
||||||
{:err, "404 not found"}
|
{:err, "404 not found"}
|
||||||
|
|
||||||
{:ok, %HTTPoison.Response{status_code: status_code, headers: headers}}
|
{:ok, %HTTPoison.Response{status_code: status_code, headers: headers}}
|
||||||
when status_code == 301 or status_code == 302 ->
|
when status_code in [301, 302] ->
|
||||||
{"Location", new_url} =
|
{"Location", new_url} =
|
||||||
Enum.find(headers, fn {name, _value} ->
|
Enum.find(headers, fn {name, _value} ->
|
||||||
name == "Location"
|
name == "Location"
|
||||||
|
|
Loading…
Reference in New Issue