[pve-devel] [RFC apiclient 2/2] use new Exception.pm class to signal errors to caller
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Dec 13 12:34:45 CET 2017
On 12/12/2017 04:18 PM, Thomas Lamprecht wrote:
> Allows a caller to access the HTTP response code, which may be useful
> to handle application logic. E.g., catching a HTTP_NOT_IMPLEMENTED
> and fallback to an older method.
> As the exception class has already some stringify methods we can
> remove some code here too.
>
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
> PVE/APIClient/LWP.pm | 26 +++++++++-----------------
> 1 file changed, 9 insertions(+), 17 deletions(-)
>
> diff --git a/PVE/APIClient/LWP.pm b/PVE/APIClient/LWP.pm
> index 4584bc0..ac9e0c7 100755
> --- a/PVE/APIClient/LWP.pm
> +++ b/PVE/APIClient/LWP.pm
> @@ -11,6 +11,7 @@ use JSON;
> use Data::Dumper; # fixme: remove
> use HTTP::Request::Common;
> use Carp;
> +use PVE::APIClient::Exception qw(raise);
>
> my $extract_data = sub {
> my ($res) = @_;
> @@ -118,10 +119,8 @@ sub login {
> $response = $exec_login->(); # try again
> }
> }
> - }
> -
> - if (!$response->is_success) {
> - die $response->status_line . "\n";
Here I tried to cleanup to much, it makes sense that we have two identical checks
as else we do not catch the case where we try again if manual fingerprint
verification is allowed.
Will send v2 which keeps this.
> + } else {
> + raise($response->status_line ."\n", code => $response->code)
> }
>
> my $res = from_json($response->decoded_content, {utf8 => 1, allow_nonref => 1});
More information about the pve-devel
mailing list