From: Hannes Duerr Date: Mon, 10 Feb 2025 14:19:24 +0000 (+0100) Subject: api request helper: use builtin method to check success of requests X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=77671ba327fa0fc6461d70f9e9e64891b58c36ab;p=matthieu%2Fpve-network.git api request helper: use builtin method to check success of requests Avoid using a regex if we have a builtin function ready to use. Signed-off-by: Hannes Duerr Tested-by: Stefan Hanreich [TL: touch up commit message] Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/Network/SDN.pm b/src/PVE/Network/SDN.pm index 0fe7c9f..1186d9e 100644 --- a/src/PVE/Network/SDN.pm +++ b/src/PVE/Network/SDN.pm @@ -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"; }