aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorwinter2025-04-03 22:06:47 +0100
committerwinter2025-04-03 22:06:47 +0100
commit44212e6248c93171ddedb51bfdb212ce8ffed695 (patch)
tree26d87e7ddbc887d5c727d1b45f09807226e71976
parentdc1deda3a02e3ebc31d4ed3a256580469cf83c0e (diff)
indicate error on failed push (status != 20x)
-rw-r--r--Digitigrade/Job/PushObject.php6
-rw-r--r--Digitigrade/Model/Instance.php11
2 files changed, 14 insertions, 3 deletions
diff --git a/Digitigrade/Job/PushObject.php b/Digitigrade/Job/PushObject.php
index 0278eb5..1f3bcd9 100644
--- a/Digitigrade/Job/PushObject.php
+++ b/Digitigrade/Job/PushObject.php
@@ -29,8 +29,9 @@ class PushObject extends Job {
$log = Logger::getInstance();
$log->info("pushing object $object->uri to server $instance->domain");
+ $successful = false;
try {
- $instance->pushObject($object);
+ $successful = $instance->pushObject($object);
} catch (EndpointMissingException $e) {
$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
@@ -43,5 +44,8 @@ class PushObject extends Job {
$log->warning("can't push to $instance->domain because a policy rejected it. giving up");
// and don't throw again, pretty much same reasoning as above
}
+ if (!$successful) {
+ throw new \RuntimeException("failed to push to $instance->domain");
+ }
}
} \ No newline at end of file
diff --git a/Digitigrade/Model/Instance.php b/Digitigrade/Model/Instance.php
index 2bcc258..35a0978 100644
--- a/Digitigrade/Model/Instance.php
+++ b/Digitigrade/Model/Instance.php
@@ -199,7 +199,14 @@ class Instance extends FetchableModel {
return false;
}
- public function pushObject(PushableModel $obj) {
+ /**
+ * Pushes the given object to this instance
+ * @param PushableModel $obj
+ * @throws EndpointMissingException if this instance has no push endpoint
+ * @throws AuthException if we aren't authenticated with the remote instance
+ * @return bool success or failure
+ */
+ public function pushObject(PushableModel $obj): bool {
if (!isset($this->endpoints->push)) {
throw new EndpointMissingException($this, 'push');
}
@@ -216,7 +223,7 @@ class Instance extends FetchableModel {
'content' => json_encode($obj)
]]);
file_get_contents($this->endpoints->push, context: $context);
- if (str_contains($http_response_header[0], '200')) {
+ if (str_contains($http_response_header[0], ' 20')) {
return true;
} elseif (str_contains($http_response_header[0], '401') || str_contains($http_response_header[0], '403')) {
// in this case we can't be certain whether it failed because wrong token or because they're not subscribed to us