diff options
author | 2024-01-29 21:51:34 +0100 | |
---|---|---|
committer | 2024-01-29 21:51:34 +0100 | |
commit | d01c462ad514c327a82e92f269c139028de0a4f7 (patch) | |
tree | 658d83caf011645c46d13e8122d212d16a928c3a /lib | |
parent | b2c8475b2c789de8c70aab5ea7b5b0ae56a2a507 (diff) | |
download | rss-bridge-d01c462ad514c327a82e92f269c139028de0a4f7.tar.gz rss-bridge-d01c462ad514c327a82e92f269c139028de0a4f7.tar.zst rss-bridge-d01c462ad514c327a82e92f269c139028de0a4f7.zip |
fix(FeedExpander): if parse fails, include offending url in exception message (#3938)
Also some refactors
Diffstat (limited to 'lib')
-rw-r--r-- | lib/FeedExpander.php | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/FeedExpander.php b/lib/FeedExpander.php index be3a8ca4..abe964e1 100644 --- a/lib/FeedExpander.php +++ b/lib/FeedExpander.php @@ -23,14 +23,20 @@ abstract class FeedExpander extends BridgeAbstract throw new \Exception(sprintf('Unable to parse xml from `%s` because we got the empty string', $url), 10); } // prepare/massage the xml to make it more acceptable - $badStrings = [ + $problematicStrings = [ ' ', '»', '’', ]; - $xmlString = str_replace($badStrings, '', $xmlString); + $xmlString = str_replace($problematicStrings, '', $xmlString); + $feedParser = new FeedParser(); - $this->feed = $feedParser->parseFeed($xmlString); + try { + $this->feed = $feedParser->parseFeed($xmlString); + } catch (\Exception $e) { + throw new \Exception(sprintf('Failed to parse xml from %s: %s', $url, create_sane_exception_message($e))); + } + $items = array_slice($this->feed['items'], 0, $maxItems); // todo: extract parse logic out from FeedParser foreach ($items as $item) { |