From ae17604eb3439d0ea9de2bae464611b9b087cd49 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 10 Oct 2019 10:04:50 +0200 Subject: [PATCH] vmware vcsa: better error handling --- apps/vmware/vcsa/restapi/custom/api.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/vmware/vcsa/restapi/custom/api.pm b/apps/vmware/vcsa/restapi/custom/api.pm index 121e9ad0b..f18614eb0 100644 --- a/apps/vmware/vcsa/restapi/custom/api.pm +++ b/apps/vmware/vcsa/restapi/custom/api.pm @@ -44,7 +44,7 @@ sub new { } if (!defined($options{noptions})) { - $options{options}->add_options(arguments => { + $options{options}->add_options(arguments => { 'hostname:s' => { name => 'hostname' }, 'port:s' => { name => 'port'}, 'proto:s' => { name => 'proto' }, @@ -220,6 +220,10 @@ sub request_api { $self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)"); $self->{output}->option_exit(); } + if ($self->{http}->get_code() != 200) { + $self->{output}->add_option_msg(short_msg => 'api request error: ' . (defined($decoded->{type}) ? $decoded->{type} : 'unknown')); + $self->{output}->option_exit(); + } return $decoded; }