Issues

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

You should be able to fix it using the following... $response is actually the body in most cases (or all I believe)


Index: Audioscrobbler.php
===================================================================
--- Audioscrobbler.php  (revision 5842)
+++ Audioscrobbler.php  (working copy)
@@ -177,7 +177,7 @@
         } else if ($response == 'No user exists with this name.') {
             throw new Zend_Http_Client_Exception('No user exists with this name');
         } else if ($request->isError()) {
-            throw new Zend_Http_Client_Exception('The web service ' . $this->_client->getUri() . ' returned the following status code: ' . $response->getStatus());
+            throw new Zend_Http_Client_Exception('The web service ' . $this->_client->getUri() . ' returned the following status code: ' . $request->getStatus() . ' ' . $request->getMessage());
         }
 
         set_error_handler(array($this, '_errorHandler'));

This looks okay to me, I'll see if I can free up some time to fix it.

Fixed in r7419 (unit tests available).

Merged to branch/release-1.0 (r7688), target changed to mini release.