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 <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>
This commit is contained in:
Hannes Duerr 2025-02-10 15:19:24 +01:00 committed by Thomas Lamprecht
parent 9829f51a48
commit 77671ba327

View 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";
}