From 7c36d47ea22390e386820dfb324090357f865857 Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Thu, 23 Jul 2009 18:13:17 +0200 Subject: [PATCH] Fixed some error handling --- lib/Zebra.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Zebra.pm b/lib/Zebra.pm index 31b4a1d..8ae40ae 100644 --- a/lib/Zebra.pm +++ b/lib/Zebra.pm @@ -120,19 +120,23 @@ sub add_time { return 0; } - my $zresponse = from_json($res->content)->{command}{response}; + my $zresponse = from_json($res->content); - if ($zresponse && $zresponse->{success} && $zresponse->{success} eq 'false') { - my @error = @{ from_json($res->content)->{command}{error} }; + unless ($zresponse->{command}{response}{success} && $zresponse->{command}{response}{success} eq 'true') { my $errorstr = ''; - foreach my $e (@error) { - if (ref($e) eq 'HASH') { - foreach my $key (keys %$e) { - if ($key ne '@attributes') { - $errorstr .= $e->{$key}; + if ($zresponse->{command}{error}) { + my @error = @{ from_json($res->content)->{command}{error} }; + foreach my $e (@error) { + if (ref($e) eq 'HASH') { + foreach my $key (keys %$e) { + if ($key ne '@attributes') { + $errorstr .= $e->{$key}; + } } } } + } elsif ($zresponse->{exception}{message}) { + $errorstr = $zresponse->{exception}{message}; } $self->{_error} = qq(Failed to post timesheet data!, error if any was: $errorstr'); warn $self->{_error}; -- 2.39.5