Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#12059 closed defect (bug) (worksforme)

fetch_feed($feedURL) throws an error when passed a bad feed...

Reported by: wickedbrilliant's profile wickedbrilliant Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9
Component: Feeds Keywords: fetch, feed
Focuses: Cc:

Description

If I call fetch_feed on a URL that is not a properly formed RSS feed, I don't generate any errors until I call a method on it, such as
$feed->get_item_quantity()
at which point it throws:
Fatal error: Call to undefined method WP_Error::get_item_quantity()

It doesn't seem to repond to:
if ($feed->error())
{

echo $feed->error();

}

It would be nice if it failed quietly
returned false returned some sort of error object. As it stands right now there is no way to catch errors.

Try it:
$feed = fetch_feed("http://www.espn.com/blah.htm");
$feed->get_item_quantity();

Change History (1)

#1 @nacin
15 years ago

  • Milestone Unassigned deleted
  • Resolution set to worksforme
  • Status changed from new to closed

On failure, fetch_feed() returns a WP_Error object instead of a Simplepie error. (You can see how this works by looking at the code directly.)

Thus, you'll need to do something like this:

$feed = fetch_feed( $url );
if ( is_wp_error( $feed ) ) {
   echo $rss->get_error_message(); // a method of WP_Error
} else {
   // do your stuff here
}
Note: See TracTickets for help on using tickets.