diff options
| author | winter | 2025-01-14 17:22:01 +0000 |
|---|---|---|
| committer | winter | 2025-01-14 17:22:01 +0000 |
| commit | 8c4109791ee0eefadf96c9d7c925da45c11a655f (patch) | |
| tree | 5e4a9c177e5ac8d5aa6b6eb8377c1aac8641a064 | |
| parent | d7940cf9470ee8377cf6484f4a20869c62d48685 (diff) | |
set up auth automatically on push failure
| -rw-r--r-- | Digitigrade/Exception/AuthException.php | 17 | ||||
| -rw-r--r-- | Digitigrade/Job/PushObject.php | 4 | ||||
| -rw-r--r-- | Digitigrade/Model/Instance.php | 3 |
3 files changed, 23 insertions, 1 deletions
diff --git a/Digitigrade/Exception/AuthException.php b/Digitigrade/Exception/AuthException.php new file mode 100644 index 0000000..4b558a4 --- /dev/null +++ b/Digitigrade/Exception/AuthException.php @@ -0,0 +1,17 @@ +<?php +namespace Digitigrade\Exception; + +use Digitigrade\Model\Instance; + +class AuthException extends \RuntimeException { + protected Instance $instance; + + public function __construct(Instance $instance, \Throwable $previous = null) { + parent::__construct("I'm not authenticated with $instance->domain", previous: $previous); + $this->instance = $instance; + } + + public function getInstance(): Instance { + return $this->instance; + } +}
\ No newline at end of file diff --git a/Digitigrade/Job/PushObject.php b/Digitigrade/Job/PushObject.php index ee5841e..e86f1d7 100644 --- a/Digitigrade/Job/PushObject.php +++ b/Digitigrade/Job/PushObject.php @@ -1,6 +1,7 @@ <?php namespace Digitigrade\Job; +use Digitigrade\Exception\AuthException; use Digitigrade\Exception\EndpointMissingException; use Digitigrade\Job; use Digitigrade\Logger; @@ -33,6 +34,9 @@ class PushObject extends Job { $log->warning("can't push to $instance->domain because it has no push endpoint. giving up"); // and don't throw again here because we want it to look successful and not be retried // reasoning: i think it's unlikely for an instance with no endpoint to suddenly acquire one + } catch (AuthException $e) { + // start auth now and hopefully by the next retry we'll be able to + $instance->beginOutboundAuth(); } } }
\ No newline at end of file diff --git a/Digitigrade/Model/Instance.php b/Digitigrade/Model/Instance.php index 2b07b9a..c689657 100644 --- a/Digitigrade/Model/Instance.php +++ b/Digitigrade/Model/Instance.php @@ -1,6 +1,7 @@ <?php namespace Digitigrade\Model; +use Digitigrade\Exception\AuthException; use Digitigrade\Exception\EndpointMissingException; use Digitigrade\GlobalConfig; use Digitigrade\Job\RefreshOutboundAuthToken; @@ -193,7 +194,7 @@ class Instance extends FetchableModel { throw new EndpointMissingException($this, 'push'); } if (!isset($this->auth->outboundToken)) { - throw new \RuntimeException("can't push to $this->domain because i don't have an outbound token for it"); + throw new AuthException($this); } if (!$this->auth->outboundPushEnabled) { throw new \RuntimeException("won't push to $this->domain because it hasn't subscribed to us"); |
