[ActivityPub][POSTMAN] Do not die on network errors

This commit is contained in:
Diogo Peralta Cordeiro 2021-07-16 18:03:12 +01:00
parent 5396f3c9d1
commit 56ece91f4c

View File

@ -87,7 +87,7 @@ class Activitypub_postman
* @param string $method request method * @param string $method request method
* @return GNUsocial_HTTPResponse * @return GNUsocial_HTTPResponse
* @throws HTTP_Request2_Exception * @throws HTTP_Request2_Exception
* @throws Exception * @throws HTTP_Request2_LogicException
* @author Diogo Cordeiro <diogo@fc.up.pt> * @author Diogo Cordeiro <diogo@fc.up.pt>
*/ */
public function send($data, $inbox, $method = 'POST') public function send($data, $inbox, $method = 'POST')
@ -224,8 +224,8 @@ class Activitypub_postman
$data = json_encode($data, JSON_UNESCAPED_SLASHES); $data = json_encode($data, JSON_UNESCAPED_SLASHES);
foreach ($this->to_inbox() as $inbox) { foreach ($this->to_inbox() as $inbox) {
try {
$res = $this->send($data, $inbox); $res = $this->send($data, $inbox);
// accumulate errors for later use, if needed // accumulate errors for later use, if needed
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) { if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
$res_body = json_decode($res->getBody(), true); $res_body = json_decode($res->getBody(), true);
@ -233,6 +233,9 @@ class Activitypub_postman
$res_body['error'] : "An unknown error occurred."; $res_body['error'] : "An unknown error occurred.";
$to_failed[$inbox] = $notice; $to_failed[$inbox] = $notice;
} }
} catch (Exception $e){
$to_failed[$inbox] = $notice;
}
} }
if (!empty($errors)) { if (!empty($errors)) {
@ -260,6 +263,7 @@ class Activitypub_postman
$data = json_encode($data, JSON_UNESCAPED_SLASHES); $data = json_encode($data, JSON_UNESCAPED_SLASHES);
foreach ($this->to_inbox() as $inbox) { foreach ($this->to_inbox() as $inbox) {
try {
$res = $this->send($data, $inbox); $res = $this->send($data, $inbox);
// accummulate errors for later use, if needed // accummulate errors for later use, if needed
@ -269,6 +273,9 @@ class Activitypub_postman
$res_body['error'] : "An unknown error occurred."; $res_body['error'] : "An unknown error occurred.";
$to_failed[$inbox] = $notice; $to_failed[$inbox] = $notice;
} }
} catch (Exception $e) {
$to_failed[$inbox] = $notice;
}
} }
if (!empty($errors)) { if (!empty($errors)) {
@ -296,6 +303,7 @@ class Activitypub_postman
$data = json_encode($data, JSON_UNESCAPED_SLASHES); $data = json_encode($data, JSON_UNESCAPED_SLASHES);
foreach ($this->to_inbox() as $inbox) { foreach ($this->to_inbox() as $inbox) {
try {
$res = $this->send($data, $inbox); $res = $this->send($data, $inbox);
// accummulate errors for later use, if needed // accummulate errors for later use, if needed
@ -305,6 +313,9 @@ class Activitypub_postman
$res_body['error'] : "An unknown error occurred."; $res_body['error'] : "An unknown error occurred.";
$to_failed[$inbox] = $notice; $to_failed[$inbox] = $notice;
} }
} catch (Exception $e) {
$to_failed[$inbox] = $notice;
}
} }
if (!empty($errors)) { if (!empty($errors)) {
@ -361,6 +372,7 @@ class Activitypub_postman
); );
foreach ($this->to_inbox() as $inbox) { foreach ($this->to_inbox() as $inbox) {
try {
$res = $this->send($data, $inbox); $res = $this->send($data, $inbox);
// accummulate errors for later use, if needed // accummulate errors for later use, if needed
@ -370,6 +382,9 @@ class Activitypub_postman
$res_body['error'] : "An unknown error occurred."; $res_body['error'] : "An unknown error occurred.";
$to_failed[$inbox] = $notice; $to_failed[$inbox] = $notice;
} }
} catch (Exception $e) {
$to_failed[$inbox] = $notice;
}
} }
if (!empty($errors)) { if (!empty($errors)) {
@ -392,6 +407,7 @@ class Activitypub_postman
$errors = []; $errors = [];
$data = json_encode($data, JSON_UNESCAPED_SLASHES); $data = json_encode($data, JSON_UNESCAPED_SLASHES);
foreach ($this->to_inbox() as $inbox) { foreach ($this->to_inbox() as $inbox) {
try {
$res = $this->send($data, $inbox); $res = $this->send($data, $inbox);
if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) { if (!($res->getStatus() == 200 || $res->getStatus() == 202 || $res->getStatus() == 409)) {
$res_body = json_decode($res->getBody(), true); $res_body = json_decode($res->getBody(), true);
@ -399,6 +415,9 @@ class Activitypub_postman
$res_body['error'] : "An unknown error occurred."; $res_body['error'] : "An unknown error occurred.";
$to_failed[$inbox] = $notice; $to_failed[$inbox] = $notice;
} }
} catch (Exception $e) {
$to_failed[$inbox] = $notice;
}
} }
if (!empty($errors)) { if (!empty($errors)) {
throw new Exception(json_encode($errors)); throw new Exception(json_encode($errors));
@ -419,6 +438,7 @@ class Activitypub_postman
$errors = []; $errors = [];
foreach ($this->to_inbox() as $inbox) { foreach ($this->to_inbox() as $inbox) {
try {
$res = $this->send($data, $inbox); $res = $this->send($data, $inbox);
// accumulate errors for later use, if needed // accumulate errors for later use, if needed
@ -427,6 +447,9 @@ class Activitypub_postman
$errors[] = isset($res_body['error']) ? $errors[] = isset($res_body['error']) ?
$res_body['error'] : "An unknown error occurred."; $res_body['error'] : "An unknown error occurred.";
} }
} catch (Exception $e) {
$to_failed[$inbox] = $notice;
}
} }
if (!empty($errors)) { if (!empty($errors)) {