Recover from errors in custom extractors

This commit is contained in:
Shadowfacts 2021-03-31 15:30:17 -04:00
parent 26b832b622
commit 33d1cac5e1
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 13 additions and 1 deletions

View File

@ -89,7 +89,19 @@ defmodule Frenzy.Pipeline.ScrapeStage do
module_name -> module_name ->
html_tree = Floki.parse(body) html_tree = Floki.parse(body)
apply(String.to_existing_atom("Elixir." <> module_name), :extract, [html_tree])
try do
apply(String.to_existing_atom("Elixir." <> module_name), :extract, [html_tree])
rescue
e ->
Logger.error(
"Encountered error extracting article content from '#{url}' with #{module_name}, falling back to default"
)
Logger.error(Exception.format(:error, e, __STACKTRACE__))
{:ok, Readability.article(body)}
end
end end
|> case do |> case do
{:ok, html} -> {:ok, html} ->