From 0b30df4b69bfdf15e34341bd8d90985bbe3ec7bd Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 28 Jul 2024 02:43:56 -0400 Subject: [PATCH] gandi: Fix processing of `PUT` error responses Before, the returned JSON wasn't even parsed -- the error handling code was reusing the parsed response from the earlier `GET`. Also, it was reading object properties that were not documented in the Gandi API documentation. --- ChangeLog.md | 2 ++ ddclient.in | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 11bd94e..f7b0f67 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -142,6 +142,8 @@ repository history](https://github.com/ddclient/ddclient/commits/master). [#719](https://github.com/ddclient/ddclient/pull/719) * `yandex`: Errors are now retried. [#719](https://github.com/ddclient/ddclient/pull/719) + * `gandi`: Fixed handling of error responses. + [#721](https://github.com/ddclient/ddclient/pull/721) ## 2023-11-23 v3.11.2 diff --git a/ddclient.in b/ddclient.in index 71c4cbb..6658bae 100755 --- a/ddclient.in +++ b/ddclient.in @@ -6952,14 +6952,12 @@ sub nic_gandi_update { ); if (!header_ok($h, $reply)) { $config{$h}{"status-$ipv"} = "bad"; - if (defined($response->{status}) && $response->{status} eq "error") { - my @errors; - for my $err (@{$response->{errors}}) { - push(@errors, $err->{description}); - } - failed("$h: " . join(", ", @errors)); + $reply =~ s/^.*?\n\n//s; + my $response = eval { decode_json($reply) }; + if (ref($response) eq 'HASH' && ($response->{message} // '') ne '') { + failed("$h: $response->{message}"); } else { - failed("$h: unexpected service response"); + failed("$h: unexpected error response: $reply"); } next; }