use a timeout of 25 seconds (5 seconds headroom for pveproxys 30s timeout)
and decode and return the error if one is returned in json form.

Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
 PVE/API2/Storage/FileRestore.pm | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/PVE/API2/Storage/FileRestore.pm b/PVE/API2/Storage/FileRestore.pm
index a4bad44..8d241d0 100644
--- a/PVE/API2/Storage/FileRestore.pm
+++ b/PVE/API2/Storage/FileRestore.pm
@@ -121,15 +121,28 @@ __PACKAGE__->register_method ({
            if $vtype ne 'backup';
 
        my $client = PVE::PBSClient->new($scfg, $storeid);
-       my $ret = $client->file_restore_list($snap, $path, $base64);
-
-       # 'leaf' is a proper JSON boolean, map to perl-y bool
-       # TODO: make PBSClient decode all bools always as 1/0?
-       foreach my $item (@$ret) {
-           $item->{leaf} = $item->{leaf} ? 1 : 0;
+       my $ret = $client->file_restore_list($snap, $path, $base64, 
['--json-error', 1, '--timeout', 25]);
+
+       if (ref($ret) eq "HASH") {
+           my $msg = $ret->{message};
+           if ($ret->{error}) {
+               if (my $code = $ret->{code}) {
+                   die PVE::Exception->new("$msg\n", code => $code);
+               } else {
+                   die "$msg\n";
+               }
+           }
+       } elsif (ref($ret) eq "ARRAY") {
+           # 'leaf' is a proper JSON boolean, map to perl-y bool
+           # TODO: make PBSClient decode all bools always as 1/0?
+           foreach my $item (@$ret) {
+               $item->{leaf} = $item->{leaf} ? 1 : 0;
+           }
+
+           return $ret;
        }
 
-       return $ret;
+       die "invalid proxmox-file-restore output";
     }});
 
 __PACKAGE__->register_method ({
-- 
2.30.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to