ZF-1307: Fatal error resulting from bug in getInfo() method
Description
Posting on behalf of [~cgraefe]; have not yet confirmed issue. Deferring to [~chartjes] for initial comment.
Thank you for implementing the interface to the Audioscrobbler web service in Zend Framework! Currently, there is an annoying bug in the private getInfo() method, though. The following code example:
$as = new Zend_Service_Audioscrobbler();
$as->set('artist', 'This is an unknown artist.');
$as->set('track', 'Track does not matter.');
$tags = $as->trackGetTopTags();
results in a PHP Fatal error:
PHP Fatal error: Call to a member function getStatus() on a non-object in /var/httpd/servers/noise.graefe.net/lib/ZendFramework-0.9.1-Beta/library/Zend/Service/Audioscrobbler.php on line 165
My suggestion is to change the error handling in getInfo() to something like this:
if ($response == 'No such path') {
throw new Zend_Http_Client_Exception('Could not find: ' . $this->_client->getUri());
} else if ($request->isError()) {
if (is_object($response)) {
throw new Zend_Http_Client_Exception('The web service ' . $this->_client->getUri() . ' returned the following status code: ' . $response->getStatus());
} else {
throw new Zend_Http_Client_Exception( $response );
}
} else {
return simplexml_load_string($response);
}
I would have opened an issue in the tracker but either I'm to blind to find the button to do so, or I'm not allowed to. :)
Comments
Posted by Eric Coleman (eric) on 2007-07-25T10:05:38.000+0000
You should be able to fix it using the following... $response is actually the body in most cases (or all I believe)
Posted by Chris Hartjes (chartjes) on 2007-08-24T13:44:45.000+0000
This looks okay to me, I'll see if I can free up some time to fix it.
Posted by Simone Carletti (weppos) on 2008-01-14T04:07:48.000+0000
Fixed in r7419 (unit tests available).
Posted by Simone Carletti (weppos) on 2008-01-29T14:39:07.000+0000
Merged to branch/release-1.0 (r7688), target changed to mini release.