]> git.puffer.fish Git - matthieu/pve-network.git/commitdiff
api request helper: use builtin method to check success of requests
authorHannes Duerr <h.duerr@proxmox.com>
Mon, 10 Feb 2025 14:19:24 +0000 (15:19 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 6 Mar 2025 09:00:21 +0000 (10:00 +0100)
Avoid using a regex if we have a builtin function ready to use.

Signed-off-by: Hannes Duerr <h.duerr@proxmox.com>
Tested-by: Stefan Hanreich <s.hanreich@proxmox.com>
 [TL: touch up commit message]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Network/SDN.pm

index 0fe7c9f488dc467396980bf0de47c345837cd615..1186d9e0591df2dff1231d0f811bdc3bbdb50148 100644 (file)
@@ -273,10 +273,10 @@ sub api_request {
     $ua->ssl_opts(verify_hostname => 0, SSL_verify_mode => 0x00);
 
     my $response = $ua->request($req);
-    my $code = $response->code;
 
-    if ($code !~ /^2(\d+)$/) {
+    if (!$response->is_success) {
        my $msg = $response->message || 'unknown';
+       my $code = $response->code;
        die "Invalid response from server: $code $msg\n";
     }