From 448eebd1d61b940028bf051f690dc7c1a0bac1ea Mon Sep 17 00:00:00 2001 From: Ramon Caballero Date: Tue, 7 Apr 2026 00:13:10 +0100 Subject: [PATCH] Centralize error handling inside UpdateDnsCommand --- src/Command/UpdateDnsCommand.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Command/UpdateDnsCommand.php b/src/Command/UpdateDnsCommand.php index 7af7bc3..193636b 100644 --- a/src/Command/UpdateDnsCommand.php +++ b/src/Command/UpdateDnsCommand.php @@ -41,26 +41,22 @@ class UpdateDnsCommand if ($result === null) { - Console::echo("Invalid JSON returned by Porkbun API:\n$raw\n"); - return self::STATUS_ERROR; + return $this->fail("Invalid JSON returned by Porkbun API: " . $raw); } if (!isset($result->status)) { - Console::echo("Porkbun API response missing 'status' field:\n$raw\n"); - return self::STATUS_ERROR; + return $this->fail("Porkbun API response missing 'status' field: " . $raw); } if ($result->status !== "SUCCESS") { - Console::echo("Porkbun API returned an error:\n$raw\n"); - return self::STATUS_ERROR; + return $this->fail("Porkbun API returned an error: " . $raw); } if (!isset($result->yourIp)) { - Console::echo("Porkbun API did not return your public IP.\n"); - return self::STATUS_ERROR; + return $this->fail("Porkbun API did not return your public IP."); } $myIp = $myIp ?? $result->yourIp; @@ -119,4 +115,11 @@ class UpdateDnsCommand return $updated ? self::STATUS_UPDATED : self::STATUS_NOTHING_TO_CHANGE; } + + private function fail(string $message): int + { + Console::echo($message); + $this->logger->log("ERROR: " . $message); + return self::STATUS_ERROR; + } }