mirror of
https://github.com/friendica/friendica
synced 2024-12-23 00:00:21 +00:00
Exception handling added at many places
This commit is contained in:
parent
e6daaf49ce
commit
518382036b
16 changed files with 174 additions and 44 deletions
|
@ -220,7 +220,12 @@ class Search
|
||||||
$return = Contact::searchByName($search, $mode, true);
|
$return = Contact::searchByName($search, $mode, true);
|
||||||
} else {
|
} else {
|
||||||
$p = $page > 1 ? 'p=' . $page : '';
|
$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()) {
|
if ($curlResult->isSuccess()) {
|
||||||
$searchResult = json_decode($curlResult->getBodyString(), true);
|
$searchResult = json_decode($curlResult->getBodyString(), true);
|
||||||
if (!empty($searchResult['profiles'])) {
|
if (!empty($searchResult['profiles'])) {
|
||||||
|
|
|
@ -588,7 +588,12 @@ class Photo
|
||||||
|
|
||||||
$filename = basename($image_url);
|
$filename = basename($image_url);
|
||||||
if (!empty($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]);
|
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
|
||||||
$img_str = $ret->getBodyString();
|
$img_str = $ret->getBodyString();
|
||||||
$type = $ret->getContentType();
|
$type = $ret->getContentType();
|
||||||
|
@ -1043,7 +1048,12 @@ class Photo
|
||||||
{
|
{
|
||||||
$filename = basename($image_url);
|
$filename = basename($image_url);
|
||||||
if (!empty($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]);
|
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
|
||||||
$img_str = $ret->getBodyString();
|
$img_str = $ret->getBodyString();
|
||||||
$type = $ret->getContentType();
|
$type = $ret->getContentType();
|
||||||
|
|
|
@ -185,18 +185,21 @@ class Media
|
||||||
|
|
||||||
// Workaround for systems that can't handle a HEAD request
|
// Workaround for systems that can't handle a HEAD request
|
||||||
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
||||||
$curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
|
try {
|
||||||
}
|
$curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
|
||||||
|
if ($curlResult->isSuccess()) {
|
||||||
if ($curlResult->isSuccess()) {
|
if (empty($media['mimetype'])) {
|
||||||
if (empty($media['mimetype'])) {
|
$media['mimetype'] = $curlResult->getContentType() ?? '';
|
||||||
$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]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1411,12 +1411,18 @@ class User
|
||||||
$photo_failure = false;
|
$photo_failure = false;
|
||||||
|
|
||||||
$filename = basename($photo);
|
$filename = basename($photo);
|
||||||
$curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
|
try {
|
||||||
if ($curlResult->isSuccess()) {
|
$curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
|
||||||
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
|
if ($curlResult->isSuccess()) {
|
||||||
$img_str = $curlResult->getBodyString();
|
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
|
||||||
$type = $curlResult->getContentType();
|
$img_str = $curlResult->getBodyString();
|
||||||
} else {
|
$type = $curlResult->getContentType();
|
||||||
|
} else {
|
||||||
|
$img_str = '';
|
||||||
|
$type = '';
|
||||||
|
}
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||||
$img_str = '';
|
$img_str = '';
|
||||||
$type = '';
|
$type = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,10 +109,20 @@ class MatchInterests extends BaseModule
|
||||||
continue;
|
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()) {
|
if (!$result->isSuccess()) {
|
||||||
// try legacy endpoint
|
// 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()) {
|
if (!$result->isSuccess()) {
|
||||||
$this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]);
|
$this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -214,7 +214,12 @@ class Probe
|
||||||
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]);
|
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]);
|
||||||
$xrd = null;
|
$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);
|
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||||
if ($curlResult->isSuccess()) {
|
if ($curlResult->isSuccess()) {
|
||||||
$xml = $curlResult->getBodyString();
|
$xml = $curlResult->getBodyString();
|
||||||
|
@ -231,7 +236,12 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ssl_connection_error && !is_object($xrd) && !empty($url)) {
|
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);
|
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||||
if ($curlResult->isTimeout()) {
|
if ($curlResult->isTimeout()) {
|
||||||
Logger::info('Probing timeout', ['url' => $url]);
|
Logger::info('Probing timeout', ['url' => $url]);
|
||||||
|
@ -447,7 +457,12 @@ class Probe
|
||||||
*/
|
*/
|
||||||
private static function getHideStatus(string $url): bool
|
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()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -886,7 +901,12 @@ class Probe
|
||||||
|
|
||||||
private static function pollZot(string $url, array $data): array
|
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()) {
|
if ($curlResult->isTimeout()) {
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -1067,7 +1087,12 @@ class Probe
|
||||||
*/
|
*/
|
||||||
private static function pollNoscrape(string $noscrape_url, array $data): array
|
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()) {
|
if ($curlResult->isTimeout()) {
|
||||||
self::$isTimeout = true;
|
self::$isTimeout = true;
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -1227,7 +1252,12 @@ class Probe
|
||||||
*/
|
*/
|
||||||
private static function pollHcard(string $hcard_url, array $data): array
|
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()) {
|
if ($curlResult->isTimeout()) {
|
||||||
self::$isTimeout = true;
|
self::$isTimeout = true;
|
||||||
return [];
|
return [];
|
||||||
|
@ -1517,7 +1547,12 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch all additional data from the feed
|
// 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()) {
|
if ($curlResult->isTimeout()) {
|
||||||
self::$isTimeout = true;
|
self::$isTimeout = true;
|
||||||
return [];
|
return [];
|
||||||
|
@ -1904,7 +1939,12 @@ class Probe
|
||||||
return '';
|
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())) {
|
if ($curlResult->isSuccess() && !empty($curlResult->getBodyString())) {
|
||||||
$noscrape = json_decode($curlResult->getBodyString(), true);
|
$noscrape = json_decode($curlResult->getBodyString(), true);
|
||||||
|
@ -1980,7 +2020,12 @@ class Probe
|
||||||
private static function updateFromFeed(array $data): string
|
private static function updateFromFeed(array $data): string
|
||||||
{
|
{
|
||||||
// Search for the newest entry in the feed
|
// 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()) {
|
if (!$curlResult->isSuccess() || !$curlResult->getBodyString()) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,10 +115,16 @@ class Delivery
|
||||||
$data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
|
$data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
$timestamp = microtime(true);
|
$timestamp = microtime(true);
|
||||||
$response = HTTPSignature::post($data, $inbox, $owner);
|
try {
|
||||||
$runtime = microtime(true) - $timestamp;
|
$response = HTTPSignature::post($data, $inbox, $owner);
|
||||||
$success = $response->isSuccess();
|
$success = $response->isSuccess();
|
||||||
$serverfail = $response->isTimeout();
|
$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) {
|
if (!$success) {
|
||||||
// 5xx errors are problems on the server. We don't need to continue delivery then.
|
// 5xx errors are problems on the server. We don't need to continue delivery then.
|
||||||
if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
|
if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
|
||||||
|
|
|
@ -996,7 +996,12 @@ class DFRN
|
||||||
|
|
||||||
$content_type = ($public_batch ? 'application/magic-envelope+xml' : 'application/json');
|
$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);
|
Item::incrementOutbound(Protocol::DFRN);
|
||||||
$xml = $postResult->getBodyString();
|
$xml = $postResult->getBodyString();
|
||||||
|
|
||||||
|
|
|
@ -2955,7 +2955,12 @@ class Diaspora
|
||||||
if (!intval(DI::config()->get('system', 'diaspora_test'))) {
|
if (!intval(DI::config()->get('system', 'diaspora_test'))) {
|
||||||
$content_type = (($public_batch) ? 'application/magic-envelope+xml' : 'application/json');
|
$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();
|
$return_code = $postResult->getReturnCode();
|
||||||
Item::incrementOutbound(Protocol::DIASPORA);
|
Item::incrementOutbound(Protocol::DIASPORA);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -230,7 +230,11 @@ class ExAuth
|
||||||
|
|
||||||
$url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user;
|
$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()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -366,7 +366,12 @@ class HTTPSignature
|
||||||
return true;
|
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_code = $postResult->getReturnCode();
|
||||||
|
|
||||||
return ($return_code >= 200) && ($return_code <= 299);
|
return ($return_code >= 200) && ($return_code <= 299);
|
||||||
|
|
|
@ -79,6 +79,7 @@ class Network
|
||||||
try {
|
try {
|
||||||
$curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
|
$curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, $options);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
Logger::notice('Got exception', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,12 @@ class ParseUrl
|
||||||
|
|
||||||
// Workaround for systems that can't handle a HEAD request. Don't retry on timeouts.
|
// 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])) {
|
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()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
|
|
|
@ -51,7 +51,12 @@ class CheckRelMeProfileLink
|
||||||
}
|
}
|
||||||
|
|
||||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
|
$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()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]);
|
Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -152,7 +152,12 @@ class OnePoll
|
||||||
|
|
||||||
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-');
|
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-');
|
||||||
Item::incrementInbound(Protocol::FEED);
|
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);
|
unlink($cookiejar);
|
||||||
Logger::debug('Polled feed', ['url' => $contact['poll'], 'http-code' => $curlResult->getReturnCode(), 'redirect-url' => $curlResult->getRedirectUrl()]);
|
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']]);
|
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()]);
|
Logger::info('Hub subscription done', ['result' => $postResult->getReturnCode()]);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,12 @@ class UpdateServerPeers
|
||||||
return;
|
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())) {
|
if (!$ret->isSuccess() || empty($ret->getBodyString())) {
|
||||||
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue