Skip to content

Commit

Permalink
Catch and report JSON error messages when available
Browse files Browse the repository at this point in the history
Don't simply die because $tx->res->json returns an undef and you can't
treat it as a hash.

Signed-off-by: Zak B. Elep <zakame@cpan.org>
  • Loading branch information
zakame committed Oct 4, 2011
1 parent db9f996 commit 0275fa3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Google/Plus.pm
Expand Up @@ -45,9 +45,12 @@ sub _request {
my $tx = $ua->get($url);
$tx->success and return $tx->res->json;

my ($message, $code) = $tx->error;
my $json_err = $tx->res->json->{error}->{message};
die "Error: $code $message ($json_err)";
my $message = $tx->error;
$tx->res->json and do {
my $json_err = $tx->res->json->{error}->{message};
$message = join ' ', $message => $json_err;
};
die "Error: $message";
}

sub new {
Expand Down

0 comments on commit 0275fa3

Please sign in to comment.