Ignore:
Timestamp:
Sep 20, 2011, 11:15:32 PM (11 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
Branches:
master, release-1.9
Children:
b7fa912
Parents:
2a42248
git-author:
Edward Z. Yang <ezyang@mit.edu> (07/12/11 09:17:04)
git-committer:
Edward Z. Yang <ezyang@mit.edu> (09/20/11 23:15:32)
Message:
Convert to async (both Facebook::Graph and us.)

Work items:
    - Documentation is all out of date
    - Think more carefully about error handling
      (right now it's delayed into the response object)
    - Really bad HTTP POST hack in Publish.pm.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Facebook/lib/Facebook/Graph/Response.pm

    r2a42248 r7777ac2  
    1313);
    1414
     15has headers => (
     16    is      => 'ro',
     17    required=> 1,
     18);
     19
     20has uri => (
     21    is      => 'ro',
     22    required=> 1,
     23);
     24
    1525has as_string => (
    1626    is      => 'ro',
     
    1828    default => sub {
    1929        my $self = shift;
    20         return $self->response->content;
     30        if (!defined $self->response) {
     31            ouch $self->headers->{Status}, $self->headers->{Reason}, $self->uri;
     32        }
     33        if ($self->headers->{Status} < 200 || $self->headers->{Status} >= 300) {
     34            my $type = $self->headers->{Status};
     35            my $message = $self->response;
     36            my $error = eval { JSON->new->decode($self->response) };
     37            unless ($@) {
     38                $type = $error->{error}{type};
     39                $message = $error->{error}{message};
     40            }
     41            ouch $type, 'Could not execute request ('.$self->uri.'): '.$message, $self->uri;
     42        }
     43        return $self->response;
    2144    },
    2245);
     
    2750    default => sub {
    2851        my $self = shift;
    29         my $response = $self->response;
    30         if ($response->is_success) {
    31             return $response->content;
    32         }
    33         else {
    34             my $message = $response->message;
    35             my $error = eval { JSON->new->decode($response->content) };
    36             unless ($@) {
    37                 $message = $error->{error}{type} . ' - ' . $error->{error}{message};
    38             }
    39             ouch $response->code, 'Could not execute request ('.$response->request->uri->as_string.'): '.$message, $response->request->uri->as_string;
    40         }
     52        return $self->as_string;
    4153    },
    4254);
Note: See TracChangeset for help on using the changeset viewer.