dnsexit2: Invert conditions to improve readability

Instead of:

    if ($success1) {
        if ($success2) {
            if ($success3) {
                # yay
            } else {
                # fail
            }
        } else {
            # fail
        }
    } else {
        # fail
    }

do:

    if (!$success1) {
        # fail
    }
    if (!$success2) {
        # fail
    }
    if (!$success3) {
        # fail
    }
    # yay
This commit is contained in:
Richard Hansen 2024-05-29 17:21:39 -04:00
parent 9b1a785c6d
commit 3e91fd02bf

View file

@ -4270,8 +4270,16 @@ sub nic_dnsexit2_update {
my $response = decode_json($reply); my $response = decode_json($reply);
# It should at least have a 'code' and 'message'. # It should at least have a 'code' and 'message'.
if (defined($response->{'code'}) and defined($response->{'message'})) { if (!defined($response->{'code'}) || !defined($response->{'message'})) {
if (exists $status{$response->{'code'}}) { failed("Did not receive expected \"code\" and \"message\" keys in server response.");
failed("Response:");
failed("%s", $response);
next;
}
if (!exists($status{$response->{'code'}})) {
failed("Status code %s is unknown!", $response->{'code'});
next;
}
# Add the server response data to the applicable array # Add the server response data to the applicable array
push(@{$status{$response->{'code'}}}, $response->{'message'}); push(@{$status{$response->{'code'}}}, $response->{'message'});
if (defined($response->{'details'})) { if (defined($response->{'details'})) {
@ -4289,15 +4297,8 @@ sub nic_dnsexit2_update {
$config{$h}{'status-ipv6'} = $status if $ipv6; $config{$h}{'status-ipv6'} = $status if $ipv6;
# Handle statuses # Handle statuses
if ($status eq 'good') { if ($status ne 'good') {
success("%s", $message); if ($status eq 'warning') {
$config{$h}{'mtime'} = $now;
for my $ipv (keys %total_payload) {
$config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content};
$config{$h}{"status-ipv$ipv"} = 'good';
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'}));
}
} elsif ($status eq 'warning') {
warning("%s", $message); warning("%s", $message);
warning("Server response: %s", $srv_message); warning("Server response: %s", $srv_message);
} elsif ($status =~ m'^(badauth|error)$') { } elsif ($status =~ m'^(badauth|error)$') {
@ -4306,13 +4307,14 @@ sub nic_dnsexit2_update {
} else { } else {
failed("This should not be possible"); failed("This should not be possible");
} }
} else { next;
failed("Status code %s is unknown!", $response->{'code'});
} }
} else { success("%s", $message);
failed("Did not receive expected \"code\" and \"message\" keys in server response."); $config{$h}{'mtime'} = $now;
failed("Response:"); for my $ipv (keys %total_payload) {
failed("%s", $response); $config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content};
$config{$h}{"status-ipv$ipv"} = 'good';
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'}));
} }
} }
} }