fix(automations): return null on any feed parse failure
Wrap FeedParser::parse in try/catch so an unexpected Throwable from third-party feed content (not just invalid XML) maps to the clean fetch_rss_malformed failure instead of bubbling up as an unhandled exception — matching the failed()-not-throw pattern of the sibling HTTP node.
This commit is contained in:
parent
b2932262cf
commit
f55d35363f
1 changed files with 13 additions and 7 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use SimplePie\Item;
|
||||
use SimplePie\SimplePie;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Parses an RSS 2.0 / Atom 1.0 / RDF feed body into normalized item arrays.
|
||||
|
|
@ -52,19 +53,24 @@ class FeedParser
|
|||
];
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>|null Null when the body is not a valid feed.
|
||||
* @return list<array<string, mixed>>|null Null when the body is not a usable feed
|
||||
* (invalid XML, or any parse failure).
|
||||
*/
|
||||
public function parse(string $body): ?array
|
||||
{
|
||||
$feed = new SimplePie;
|
||||
$feed->enable_cache(false);
|
||||
$feed->set_raw_data($body);
|
||||
try {
|
||||
$feed = new SimplePie;
|
||||
$feed->enable_cache(false);
|
||||
$feed->set_raw_data($body);
|
||||
|
||||
if (! @$feed->init()) {
|
||||
if (! @$feed->init()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array_map(fn (Item $item): array => $this->normalize($item), $feed->get_items());
|
||||
} catch (Throwable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array_map(fn (Item $item): array => $this->normalize($item), $feed->get_items());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue