fix(FeedExpander): if parse fails, include offending url in exception message (#3938)

Also some refactors
This commit is contained in:
Dag 2024-01-29 21:51:34 +01:00 committed by GitHub
parent b2c8475b2c
commit d01c462ad5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 41 deletions

View file

@ -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) {