From 2c9be9d1697ebc62c15bf5f19571fe507b713e36 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 4 Sep 2013 13:37:28 +0200 Subject: [PATCH] improve error message --- PVE/API2Client.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PVE/API2Client.pm b/PVE/API2Client.pm index 4d4e5e9c..c573050b 100755 --- a/PVE/API2Client.pm +++ b/PVE/API2Client.pm @@ -107,8 +107,9 @@ sub call { #print "RESP: " . Dumper($response) . "\n"; + my $ct = $response->header('Content-Type'); + if ($response->is_success) { - my $ct = $response->header('Content-Type'); die "got unexpected content type" if $ct !~ m|application/json|; @@ -116,7 +117,20 @@ sub call { } else { - die $response->status_line . "\n"; + my $msg = $response->status_line . "\n"; + eval { + return if $ct !~ m|application/json|; + my $res = from_json($response->decoded_content, {utf8 => 1, allow_nonref => 1}); + if (my $errors = $res->{errors}) { + foreach my $key (keys $errors) { + my $m = $errors->{$key}; + chomp($m); + $m =~s/\n/ -- /g; + $msg .= " $key: $m\n"; + } + } + }; + die $msg; } } -- 2.39.5