Exception error without message!
Hello
I'm running a loop over more than 10,000 users were I set oauth with their twitter account (already authorised) and post a status to the twitter account
I'm facing a random error with different users (not sure till now if this is linked to the user accounts) that the function $twitterObj->post_statusesUpdate with throw exception but no error message with it!
Im using API 1.1 (not sure if the same case with version 1)
I did small check by changing the below code in EpiTwitter.php
if(isset($accessible[$name]) && $accessible[$name])
return $this->$name;
elseif(($this->code < 200 || $this->code >= 400) && !isset($accessible[$name]))
EpiTwitterException::raise($this->__resp, $this->debug);
To
if(isset($accessible[$name]) && $accessible[$name]){
return $this->$name;
}elseif(($this->code < 200 || $this->code >= 400) && !isset($accessible[$name])){
$TMPTMP = array($name,$accessible,$this->code,$this->__resp,$this->debug);
@mail('[email protected]', 'EpiTwitter', print_r($TMPTMP,true));
EpiTwitterException::raise($this->__resp, $this->debug);
}
and now I got this message in my email
Array ( [0] => response [1] => Array ( [responseText] => 1 [headers] => 1 [code] => 1 )
[2] => 403
[3] => EpiCurlManager Object
(
[key:EpiCurlManager:private] => Resource id #15
[epiCurl:EpiCurlManager:private] => EpiCurl Object
(
[mc:EpiCurl:private] => Resource id #14
[msgs:EpiCurl:private] =>
[running:EpiCurl:private] =>
[execStatus:EpiCurl:private] =>
[selectStatus:EpiCurl:private] =>
[sleepIncrement:EpiCurl:private] => 1.1
[requests:EpiCurl:private] => Array
(
[Resource id #15] => Resource id #15
)
[responses:EpiCurl:private] => Array
(
[Resource id #15] => Array
(
[headers] => Array
(
[cache-control] => no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[content-encoding] => gzip
[content-length] => 77
[content-type] => application/json; charset=utf-8
[date] => Wed, 20 Mar 2013 05:10:02 GMT
[expires] => Tue, 31 Mar 1981 05:00:00 GMT
[last-modified] => Wed, 20 Mar 2013 05:10:02 GMT
[pragma] => no-cache
[server] => tfe
[set-cookie] => guest_id=v1%3A19216; Domain=.twitter.com; Path=/; Expires=Fri, 20-Mar-2015 05:10:02 UTC
[status] => 403 Forbidden
[vary] => Accept-Encoding
[x-access-level] => read-write
[x-frame-options] => SAMEORIGIN
[x-mid] => 14f2a381f7c3217bb6
[x-runtime] => 0.05954
[x-transaction] => 74054b2c9bb
[x-transaction-mask] => a6183ffa5ef1145580d934
)
[data] => {"errors":[{"code":187,"message":"Status is a duplicate"}]}
[code] => 403
[time] => 0.663101
[length] => 77
[type] => application/json; charset=utf-8
[url] => https://api.twitter.com/1.1/statuses/update.json
)
)
[properties:EpiCurl:private] => Array
(
[code] => 2097154
[time] => 3145731
[length] => 3145743
[type] => 1048594
[url] => 1048577
)
)
)
[4] => 1
)
so it seems the error I'm getting from Twitter is "{"errors":[{"code":187,"message":"Status is a duplicate"}]}"
but I'm not sure why I don't get it in the exception error message.
what do you think?
Thanks
In a try/catch does getMessage return the json string?
no, this is the issues, it doesn't return any thing
one thing I did just now is to change class EpiTwitterException to add the following
class EpiTwitterException extends Exception { public static function raise($response, $debug) { $TMPTMP = array($response->code,$response->data); @mail('[email protected]', 'EpiTwitter', print_r($TMPTMP,true));
$message = $response->data;
switch($response->code)
{
case 400:
throw new EpiTwitterBadRequestException($message, $response->code);
case 401:
throw new EpiTwitterNotAuthorizedException($message, $response->code);
case 403:
throw new EpiTwitterForbiddenException($message, $response->code);
case 404:
throw new EpiTwitterNotFoundException($message, $response->code);
case 406:
throw new EpiTwitterNotAcceptableException($message, $response->code);
case 420:
throw new EpiTwitterEnhanceYourCalmException($message, $response->code);
case 500:
throw new EpiTwitterInternalServerException($message, $response->code);
case 502:
throw new EpiTwitterBadGatewayException($message, $response->code);
case 503:
throw new EpiTwitterServiceUnavailableException($message, $response->code);
default:
throw new EpiTwitterException($message, $response->code);
}
} }
and it seems to be working fine, I can get the json code by email
but in my code , no output from getMessage
try {
$twitterObj = getTwitterObj($Token_Key,$Token_Secret);
$twitterObj->post_statusesUpdate(array('trim_user'=>true,'include_entities'=>false,'status'=>$Tweet['tweet']));
unset($twitterObj);
}catch (Exception $e) {
print 'Exception: ' . $e->getMessage();
print "\n";
if(($e->getMessage())==''){
echo 'Something wrong!';
mail(ADMIN_EMAIL, '[Error] Twitter Error', $e->getMessage());
}
}
also when I do print_r($e), it seems to me that the unset is not working and I can see the object $twitterObj keeps growing with all previous post that I did for other users in the loop (PHP bug?)