Skip to content
Browse files

Catch and report JSON error messages when available

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...
1 parent db9f996 commit 0275fa30d1619154242fd97065fc3c27a70aed96 @zakame committed Oct 4, 2011
Showing with 6 additions and 3 deletions.
  1. +6 −3 lib/Google/Plus.pm
View
9 lib/Google/Plus.pm
@@ -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 {

0 comments on commit 0275fa3

Please sign in to comment.
Something went wrong with that request. Please try again.