]> git.mjollnir.org Git - tks.git/commitdiff
Fixed some error handling
authorPenny Leach <penny@mjollnir.org>
Thu, 23 Jul 2009 16:13:17 +0000 (18:13 +0200)
committerPenny Leach <penny@mjollnir.org>
Thu, 23 Jul 2009 16:13:17 +0000 (18:13 +0200)
lib/Zebra.pm

index 31b4a1d22dcb1c4f3f03990c41113a4d397a70c6..8ae40ae8916c29b666f6712595861cedeb257b8f 100644 (file)
@@ -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};