]> git.mxchange.org Git - friendica.git/commitdiff
Exception handling added at many places
authorMichael <heluecht@pirati.ca>
Sun, 25 Aug 2024 18:35:24 +0000 (18:35 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 25 Aug 2024 18:35:24 +0000 (18:35 +0000)
16 files changed:
src/Core/Search.php
src/Model/Photo.php
src/Model/Post/Media.php
src/Model/User.php
src/Module/Contact/MatchInterests.php
src/Network/Probe.php
src/Protocol/ActivityPub/Delivery.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Security/ExAuth.php
src/Util/HTTPSignature.php
src/Util/Network.php
src/Util/ParseUrl.php
src/Worker/CheckRelMeProfileLink.php
src/Worker/OnePoll.php
src/Worker/UpdateServerPeers.php

index e9ec395ab3fae4f258eb34051ae369bb0d5a482b..776a0a0e50b433961e0a2782a2df891d4d6a0606 100644 (file)
@@ -220,7 +220,12 @@ class Search
                        $return = Contact::searchByName($search, $mode, true);
                } else {
                        $p = $page > 1 ? 'p=' . $page : '';
-                       $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]);
+                       try {
+                               $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]);
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               return [];
+                       }
                        if ($curlResult->isSuccess()) {
                                $searchResult = json_decode($curlResult->getBodyString(), true);
                                if (!empty($searchResult['profiles'])) {
index d2dd36975a9df4ecbf40c8e76de78f289a0bce94..e2d38241d88abbcd97e9f0027b36db876b9830f7 100644 (file)
@@ -588,7 +588,12 @@ class Photo
 
                $filename = basename($image_url);
                if (!empty($image_url)) {
-                       $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+                       try {
+                               $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               return false;
+                       }
                        Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
                        $img_str = $ret->getBodyString();
                        $type = $ret->getContentType();
@@ -1043,7 +1048,12 @@ class Photo
        {
                $filename = basename($image_url);
                if (!empty($image_url)) {
-                       $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+                       try {
+                               $ret = DI::httpClient()->get($image_url, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]);
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               return [];
+                       }
                        Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
                        $img_str = $ret->getBodyString();
                        $type = $ret->getContentType();
index 033ae0fbc899477ea5a844d0d3293c2d090023d2..b62771274ebb68bb3e42f4ce348a622526ae0db7 100644 (file)
@@ -185,18 +185,21 @@ class Media
 
                        // Workaround for systems that can't handle a HEAD request
                        if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
-                               $curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
-                       }
-
-                       if ($curlResult->isSuccess()) {
-                               if (empty($media['mimetype'])) {
-                                       $media['mimetype'] = $curlResult->getContentType() ?? '';
+                               try {
+                                       $curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
+                                       if ($curlResult->isSuccess()) {
+                                               if (empty($media['mimetype'])) {
+                                                       $media['mimetype'] = $curlResult->getContentType() ?? '';
+                                               }
+                                               if (empty($media['size'])) {
+                                                       $media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
+                                               }
+                                       } else {
+                                               Logger::notice('Could not fetch head', ['media' => $media]);
+                                       }
+                               } catch (\Throwable $th) {
+                                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
                                }
-                               if (empty($media['size'])) {
-                                       $media['size'] = (int)($curlResult->getHeader('Content-Length')[0] ?? 0);
-                               }
-                       } else {
-                               Logger::notice('Could not fetch head', ['media' => $media]);
                        }
                }
 
index 87caab1b6a4473c9252b5d4cc5b535a0c5aa6ea1..2a68e8f89937ad15a6502265122d511ff506ecc2 100644 (file)
@@ -1411,12 +1411,18 @@ class User
                        $photo_failure = false;
 
                        $filename = basename($photo);
-                       $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
-                       if ($curlResult->isSuccess()) {
-                               Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
-                               $img_str = $curlResult->getBodyString();
-                               $type = $curlResult->getContentType();
-                       } else {
+                       try {
+                               $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
+                               if ($curlResult->isSuccess()) {
+                                       Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
+                                       $img_str = $curlResult->getBodyString();
+                                       $type = $curlResult->getContentType();
+                               } else {
+                                       $img_str = '';
+                                       $type = '';
+                               }
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
                                $img_str = '';
                                $type = '';
                        }
index 8ebfe2a49ff3f97230ef1d77df70836b848d44f1..69713ef7461af7b584b97e4deb2e639337b6c4a1 100644 (file)
@@ -109,10 +109,20 @@ class MatchInterests extends BaseModule
                                continue;
                        }
 
-                       $result = $this->httpClient->post($server . '/search/user/tags', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+                       try {
+                               $result = $this->httpClient->post($server . '/search/user/tags', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+                       } catch (\Throwable $th) {
+                               $this->logger->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               continue;
+                       }
                        if (!$result->isSuccess()) {
                                // try legacy endpoint
-                               $result = $this->httpClient->post($server . '/msearch', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+                               try {
+                                       $result = $this->httpClient->post($server . '/msearch', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
+                               } catch (\Throwable $th) {
+                                       $this->logger->notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                                       continue;
+                               }
                                if (!$result->isSuccess()) {
                                        $this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]);
                                        continue;
index 1fa9412d9c94b2067cb70d3cdd44bd0e2e64c354..e290553a701235686513782309540f93c50fb62e 100644 (file)
@@ -214,7 +214,12 @@ class Probe
                Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]);
                $xrd = null;
 
-               $curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return [];
+               }
                $ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
                if ($curlResult->isSuccess()) {
                        $xml = $curlResult->getBodyString();
@@ -231,7 +236,12 @@ class Probe
                }
 
                if ($ssl_connection_error && !is_object($xrd) && !empty($url)) {
-                       $curlResult = DI::httpClient()->get($url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+                       try {
+                               $curlResult = DI::httpClient()->get($url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               return [];
+                       }
                        $connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
                        if ($curlResult->isTimeout()) {
                                Logger::info('Probing timeout', ['url' => $url]);
@@ -447,7 +457,12 @@ class Probe
         */
        private static function getHideStatus(string $url): bool
        {
-               $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return false;
+               }
                if (!$curlResult->isSuccess()) {
                        return false;
                }
@@ -886,7 +901,12 @@ class Probe
 
        private static function pollZot(string $url, array $data): array
        {
-               $curlResult = DI::httpClient()->get($url, 'application/x-zot+json', [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($url, 'application/x-zot+json', [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return $data;
+               }
                if ($curlResult->isTimeout()) {
                        return $data;
                }
@@ -1067,7 +1087,12 @@ class Probe
         */
        private static function pollNoscrape(string $noscrape_url, array $data): array
        {
-               $curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return $data;
+               }
                if ($curlResult->isTimeout()) {
                        self::$isTimeout = true;
                        return $data;
@@ -1227,7 +1252,12 @@ class Probe
         */
        private static function pollHcard(string $hcard_url, array $data): array
        {
-               $curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return [];
+               }
                if ($curlResult->isTimeout()) {
                        self::$isTimeout = true;
                        return [];
@@ -1517,7 +1547,12 @@ class Probe
                }
 
                // Fetch all additional data from the feed
-               $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return [];
+               }
                if ($curlResult->isTimeout()) {
                        self::$isTimeout = true;
                        return [];
@@ -1904,7 +1939,12 @@ class Probe
                        return '';
                }
 
-               $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return '';
+               }
 
                if ($curlResult->isSuccess() && !empty($curlResult->getBodyString())) {
                        $noscrape = json_decode($curlResult->getBodyString(), true);
@@ -1980,7 +2020,12 @@ class Probe
        private static function updateFromFeed(array $data): string
        {
                // Search for the newest entry in the feed
-               $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               try {
+                       $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return '';
+               }
                if (!$curlResult->isSuccess() || !$curlResult->getBodyString()) {
                        return '';
                }
index f12e838ca10a9bece07504ba4a2d9739cdb88f36..7a7d484b8d03505186435b58b6a5a1df20e057f5 100644 (file)
@@ -115,10 +115,16 @@ class Delivery
                        $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
                        if (!empty($data)) {
                                $timestamp  = microtime(true);
-                               $response   = HTTPSignature::post($data, $inbox, $owner);
-                               $runtime    = microtime(true) - $timestamp;
-                               $success    = $response->isSuccess();
-                               $serverfail = $response->isTimeout();
+                               try {
+                                       $response   = HTTPSignature::post($data, $inbox, $owner);
+                                       $success    = $response->isSuccess();
+                                       $serverfail = $response->isTimeout();
+                               } catch (\Throwable $th) {
+                                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                                       $success    = false;
+                                       $serverfail = true;
+                               }
+                               $runtime = microtime(true) - $timestamp;
                                if (!$success) {
                                        // 5xx errors are problems on the server. We don't need to continue delivery then.
                                        if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
index 4d24a76282363447c7d34590052cadd7ea56e679..1cd5a39511c6fbc64bc9a9a72153e0d9202bcc34 100644 (file)
@@ -996,7 +996,12 @@ class DFRN
 
                $content_type = ($public_batch ? 'application/magic-envelope+xml' : 'application/json');
 
-               $postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DFRN);
+               try {
+                       $postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DFRN);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return -25;
+               }
                Item::incrementOutbound(Protocol::DFRN);
                $xml = $postResult->getBodyString();
 
index b706a4007564b336edce80713a7a7d9991c849eb..f449ed01872a3835da9938ec7dfb1c7b4d8851d7 100644 (file)
@@ -2955,7 +2955,12 @@ class Diaspora
                if (!intval(DI::config()->get('system', 'diaspora_test'))) {
                        $content_type = (($public_batch) ? 'application/magic-envelope+xml' : 'application/json');
 
-                       $postResult = DI::httpClient()->post($dest_url . '/', $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DIASPORA);
+                       try {
+                               $postResult = DI::httpClient()->post($dest_url . '/', $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DIASPORA);
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               return 0;
+                       }
                        $return_code = $postResult->getReturnCode();
                        Item::incrementOutbound(Protocol::DIASPORA);
                } else {
index 5c229798418cedb3b426696e2b84175bb0237c96..43aff9548797c2588ebfd2ad526913bd9b546579 100644 (file)
@@ -230,7 +230,11 @@ class ExAuth
 
                $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user;
 
-               $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+               try {
+                       $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+               } catch (\Throwable $th) {
+                       return false;
+               }
 
                if (!$curlResult->isSuccess()) {
                        return false;
index 8b03a1211a017462360d0644c6fd473053559bfd..d7679abd1fa6477e0e39f162254977f900d91dda 100644 (file)
@@ -366,7 +366,12 @@ class HTTPSignature
                        return true;
                }
 
-               $postResult = self::post($data, $target, $owner);
+               try {
+                       $postResult = self::post($data, $target, $owner);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return false;
+               }
                $return_code = $postResult->getReturnCode();
 
                return ($return_code >= 200) && ($return_code <= 299);
index a428f0440c076aabbafe8303c1fa9e9715a71aab..a7e2fa536a3b68eba81da920481ad9bc8f65e31a 100644 (file)
@@ -79,6 +79,7 @@ class Network
                                try {
                                        $curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
                                } catch (\Exception $e) {
+                                       Logger::notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
                                        return false;
                                }
                        }
index 83fa1fe912b1f611b67dc118a661ea29d710b245..51967403614ea259b74ac685ae70070c70fa90cc 100644 (file)
@@ -65,7 +65,12 @@ class ParseUrl
 
                // Workaround for systems that can't handle a HEAD request. Don't retry on timeouts.
                if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() >= 400) && !in_array($curlResult->getReturnCode(), [408, 504])) {
-                       $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options));
+                       try {
+                               $curlResult = DI::httpClient()->get($url, $accept, array_merge([HttpClientOptions::CONTENT_LENGTH => 1000000], $options));
+                       } catch (\Throwable $th) {
+                               Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                               return [];
+                       }
                }
 
                if (!$curlResult->isSuccess()) {
index dde18bea370d80fb8d52eab7a014e7ea29c38329..0aeaf49c2ccee0107adea0599683c47d216d8905 100644 (file)
@@ -51,7 +51,12 @@ class CheckRelMeProfileLink
                }
 
                $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
-               $curlResult  = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+               try {
+                       $curlResult = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return;
+               }
                if (!$curlResult->isSuccess()) {
                        Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]);
                        return;
index 2686f00f7cb928f2a8ff1d01bbbab26314cedf9a..a305f85d5e499d3e29eff6ebadcf408345bbfa7f 100644 (file)
@@ -152,7 +152,12 @@ class OnePoll
 
                $cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-');
                Item::incrementInbound(Protocol::FEED);
-               $curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::REQUEST => HttpClientRequest::FEEDFETCHER]);
+               try {
+                       $curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::REQUEST => HttpClientRequest::FEEDFETCHER]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return false;
+               }
                unlink($cookiejar);
                Logger::debug('Polled feed', ['url' => $contact['poll'], 'http-code' => $curlResult->getReturnCode(), 'redirect-url' => $curlResult->getRedirectUrl()]);
 
@@ -492,7 +497,12 @@ class OnePoll
                        Contact::update(['hub-verify' => $verify_token], ['id' => $contact['id']]);
                }
 
-               $postResult = DI::httpClient()->post($url, $params, [], 0, HttpClientRequest::PUBSUB);
+               try {
+                       $postResult = DI::httpClient()->post($url, $params, [], 0, HttpClientRequest::PUBSUB);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return false;
+               }
 
                Logger::info('Hub subscription done', ['result' => $postResult->getReturnCode()]);
 
index 3df71d42fc8679cd4e106c7d1da62436d78f0c8c..9c5cce731b6a9b74c37469cfa639de9154ddb995 100644 (file)
@@ -32,7 +32,12 @@ class UpdateServerPeers
                        return;
                }
 
-               $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]);
+               try {
+                       $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]);
+               } catch (\Throwable $th) {
+                       Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
+                       return;
+               }
                if (!$ret->isSuccess() || empty($ret->getBodyString())) {
                        Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
                        return;