semifor / net-twitter-lite

A lighter weight (non-Moose) Perl interface to the Twitter API
Other
26 stars 11 forks source link

NET::Twitter:Lite Twitter is over capacity problem #5

Closed RuZniki closed 12 years ago

RuZniki commented 12 years ago

Hi. I've find some problem with your module. It happens when twiiter return http://twitter.com/503 error You wait it wiil be in json, but it is html. And api method return empty array.

I've find issue for twitter https://dev.twitter.com/issues/15 but until it will fix by twitter dev team, i've try to fix sub _parse_result (1682) with adding (1689-1691)

sub _parseresult { my ($self, $res) = @;

# workaround for Laconica API returning bools as strings
# (Fixed in Laconi.ca 0.7.4)
my $content = $res->content;
$content =~ s/^"(true|false)"$/$1/;
if ($content =~ /\<h2\>Twitter is over capacity.\<\/h2\>/) {
    die Net::Twitter::Lite::Error->new(http_response => $res);
}
my $obj = $self->_from_json($content);

# Twitter sometimes returns an error with status code 200
if ( $obj && ref $obj eq 'HASH' && exists $obj->{error} ) {
    die Net::Twitter::Lite::Error->new(twitter_error => $obj, http_response => $res);
}

return $obj if $res->is_success && defined $obj;

my $error = Net::Twitter::Lite::Error->new(http_response => $res);
$error->twitter_error($obj) if ref $obj;

die $error;

}

Hope this post help you.

RuZniki commented 12 years ago

maybe this will be better die Net::Twitter::Lite::Error->new(error => 'Twitter is over capacity',http_response => $res);

semifor commented 12 years ago

I don't see any difference in behavior between the original code and the code you modified. Without the code you added, $obj is undefined, because there is no JSON content. So, it falls through to "die $error" with $error set exactly the way you set it.

In my applications, I simple check $@->code. If it's 503, I know twitter is over capacity.

What am I missing?

RuZniki commented 12 years ago

OK sorry, but i have some problem with TWITTER API, i thought it was problem with module.