Generate an error when parsing a feed with no data

This commit is contained in:
Shadowfacts 2022-04-11 16:18:12 -04:00
parent 4b404c1de1
commit dc0f5964a9
1 changed files with 7 additions and 1 deletions

View File

@ -23,7 +23,13 @@ defmodule FeedParser do
"""
@spec parse(data :: String.t(), content_type :: String.t(), parsers :: [module()]) ::
{:ok, feed :: FeedParser.Feed.t()} | {:error, reason :: String.t()}
def parse(data, content_type, parsers \\ @default_parsers) when is_binary(data) do
def parse(data, content_type, parsers \\ @default_parsers)
def parse(nil, _, _) do
{:error, "no data"}
end
def parse(data, content_type, parsers) when is_binary(data) do
parsers
|> Enum.reduce_while(false, fn parser, acc ->
case parser.accepts(data, content_type) do