Centralize error handling inside UpdateDnsCommand
This commit is contained in:
parent
1cbe008a86
commit
448eebd1d6
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue