aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2024-01-29 21:51:34 +0100
committerGravatar GitHub <noreply@github.com> 2024-01-29 21:51:34 +0100
commitd01c462ad514c327a82e92f269c139028de0a4f7 (patch)
tree658d83caf011645c46d13e8122d212d16a928c3a /lib
parentb2c8475b2c789de8c70aab5ea7b5b0ae56a2a507 (diff)
downloadrss-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.php12
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 = [
'&nbsp;',
'&raquo;',
'&rsquo;',
];
- $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) {