Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Twitter plugin bugfix: Avoid null error_text field error
  • Loading branch information
ginatrapani committed Jun 7, 2012
1 parent 7a9d978 commit 1cf8fe3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
10 changes: 7 additions & 3 deletions webapp/plugins/twitter/model/class.TwitterAPIAccessorOAuth.php
Expand Up @@ -211,20 +211,24 @@ public function parseJSON($data) {
* @return array Error
*/
public function parseError($data) {
$parsed_payload = array();
$parsed_payload = array('request'=>'', 'error'=>'');
try {
$xml = $this->createParserFromString(utf8_encode($data));
if ($xml !== false) {
$root = $xml->getName();
switch ($root) {
case 'hash':
$parsed_payload = array('request'=>$xml->request, 'error'=>$xml->error);
$parsed_payload['request'] = $xml->request;
$parsed_payload['error'] = $xml->error;
break;
case 'errors':
$parsed_payload['error'] = $xml->error;
break;
default:
break;
}
}
} catch(Exception $e) {
} catch (Exception $e) {
$logger = Logger::getInstance();
$logger->logUserError('parseError Exception caught: ' . $e->getMessage(), __METHOD__.','.__LINE__);
}
Expand Down
12 changes: 6 additions & 6 deletions webapp/plugins/twitter/model/class.TwitterCrawler.php
Expand Up @@ -338,8 +338,8 @@ private function fetchAndAddTweetRepliedTo($tid) {
}
} elseif ($cURL_status == 404 || $cURL_status == 403) {
$e = $this->api->parseError($twitter_data);
$ped = DAOFactory::getDAO('PostErrorDAO');
$ped->insertError($tid, 'twitter', $cURL_status, $e['error'], $this->user->user_id);
$posterror_dao = DAOFactory::getDAO('PostErrorDAO');
$posterror_dao->insertError($tid, 'twitter', $cURL_status, $e['error'], $this->user->user_id);
$status_message = 'Error saved to tweets.';
}
$this->logger->logInfo($status_message, __METHOD__.','.__LINE__);
Expand Down Expand Up @@ -1053,8 +1053,8 @@ public function fetchFriendTweetsAndFriends() {
$this->fetchUserFriendsByIDs($stale_friend->user_id, $fd);
} elseif ($cURL_status == 401 || $cURL_status == 404) {
$e = $this->api->parseError($twitter_data);
$ued = DAOFactory::getDAO('UserErrorDAO');
$ued->insertError($stale_friend->user_id, $cURL_status,
$usererror_dao = DAOFactory::getDAO('UserErrorDAO');
$usererror_dao->insertError($stale_friend->user_id, $cURL_status,
(isset($e['error']))?$e['error']:$twitter_data,
$this->user->user_id, 'twitter');
$this->logger->logInfo('User error saved', __METHOD__.','.__LINE__);
Expand Down Expand Up @@ -1190,8 +1190,8 @@ private function fetchAndAddUser($fid, $source) {
}
} elseif ($cURL_status == 404) {
$e = $this->api->parseError($twitter_data);
$ued = DAOFactory::getDAO('UserErrorDAO');
$ued->insertError($fid, $cURL_status, $e['error'], $this->user->user_id, 'twitter');
$usererror_dao = DAOFactory::getDAO('UserErrorDAO');
$usererror_dao->insertError($fid, $cURL_status, $e['error'], $this->user->user_id, 'twitter');
$status_message = 'User error saved.';
}
$this->logger->logInfo($status_message, __METHOD__.','.__LINE__);
Expand Down
14 changes: 14 additions & 0 deletions webapp/plugins/twitter/tests/TestOfTwitterAPIAccessorOAuth.php
Expand Up @@ -145,5 +145,19 @@ public function testParseError() {

$this->assertEqual($results['error'], 'Not found');
$this->assertEqual($results['request'], '/statuses/user_timeline/ginatrasdfasdfasdapani.xml?count=100');

//Public statuses
$twitter_data = $to->http(
'https://twitter.com/statuses/user_timeline/ginatrasdfasdfasdapani_noerrorhash.xml?count=100');

$api = new CrawlerTwitterAPIAccessorOAuth('111', '222', 1234, 1234, 5, 3200, 5, 350);

$results = $api->parseError($twitter_data);

$this->debug(Utils::varDumpToString($results));

$this->assertEqual($results['error'], 'Sorry, that page does not exist');
$this->assertEqual($results['request'], '');

}
}
@@ -0,0 +1,3 @@
<errors>
<error code="34">Sorry, that page does not exist</error>
</errors>

0 comments on commit 1cf8fe3

Please sign in to comment.