Changeset f0550c5


Ignore:
Timestamp:
Apr 6, 2009, 9:16:09 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
b25b5a4
Parents:
4ea78a8
Message:
Handle Twitter being down better.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter.pm

    r4ea78a8 rf0550c5  
    2222use HTML::Entities;
    2323
    24 my $twitter;
     24our $twitter;
    2525my $user     = BarnOwl::zephyr_getsender();
    2626my ($class)  = ($user =~ /(^[^@]+)/);
     
    145145sub twitter_error {
    146146    my $ratelimit = $twitter->rate_limit_status;
    147     unless(defined($ratelimit)) {
     147    unless(defined($ratelimit) && ref($ratelimit) eq 'HASH') {
    148148        # Twitter's just sucking, sleep for 5 minutes
    149149        $last_direct_poll = $last_poll = time + 60*5;
     
    151151        return;
    152152    }
    153     if($ratelimit->{remaining_hits} <= 0) {
     153    if(exists($ratelimit->{remaining_hits})
     154       && $ratelimit->{remaining_hits} <= 0) {
    154155        $last_direct_poll = $last_poll = $ratelimit->{reset_time_in_seconds};
    155156        die("Twitter: ratelimited until " . $ratelimit->{reset_time} . "\n");
     157    } elsif(exists($ratelimit->{error})) {
     158        die("Twitter: ". $ratelimit->{error} . "\n");
     159        $last_direct_poll = $last_poll = time + 60*20;
    156160    }
    157161}
     
    163167
    164168    my $timeline = $twitter->friends_timeline( { since_id => $last_id } );
    165     unless(defined($timeline) && ref($timeline)) {
     169    unless(defined($timeline) && ref($timeline) eq 'ARRAY') {
    166170        twitter_error();
    167171        return;
     
    195199
    196200    my $direct = $twitter->direct_messages( { since_id => $last_direct } );
    197     unless(defined($direct) && ref($direct)) {
     201    unless(defined($direct) && ref($direct) eq 'ARRAY') {
    198202        twitter_error();
    199203        return;
Note: See TracChangeset for help on using the changeset viewer.