From b76634ea0c60d4d26204f13d6d05225116d0ccb0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 29 Aug 2021 13:37:08 +0200 Subject: [PATCH] Catch TransferExceptions for HTTPClient::finalUrl() in case the headers are empty --- src/Network/HTTPClient.php | 2 +- src/Network/IHTTPClient.php | 5 ++++- src/Protocol/Feed.php | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Network/HTTPClient.php b/src/Network/HTTPClient.php index 053c65c0d1..301d4c3a7a 100644 --- a/src/Network/HTTPClient.php +++ b/src/Network/HTTPClient.php @@ -220,7 +220,7 @@ class HTTPClient implements IHTTPClient $urlResult = $this->resolver->resolveURL($url); if ($urlResult->didErrorOccur()) { - throw new TransferException($urlResult->getErrorMessageString()); + throw new TransferException($urlResult->getErrorMessageString(), $urlResult->getHTTPStatusCode()); } return $urlResult->getURL(); diff --git a/src/Network/IHTTPClient.php b/src/Network/IHTTPClient.php index 8716805532..0b51d6480e 100644 --- a/src/Network/IHTTPClient.php +++ b/src/Network/IHTTPClient.php @@ -21,6 +21,8 @@ namespace Friendica\Network; +use GuzzleHttp\Exception\TransferException; + /** * Interface for calling HTTP requests and returning their responses */ @@ -124,7 +126,8 @@ interface IHTTPClient * @param string $url A user-submitted URL * * @return string A canonical URL - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * + * @throws TransferException In case there's an error during the resolving */ public function finalUrl(string $url); } diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 8ab7066ea9..07fa04518a 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -42,6 +42,7 @@ use Friendica\Util\ParseUrl; use Friendica\Util\Proxy; use Friendica\Util\Strings; use Friendica\Util\XML; +use GuzzleHttp\Exception\TransferException; /** * This class contain functions to import feeds (RSS/RDF/Atom) @@ -297,7 +298,11 @@ class Feed $orig_plink = $item["plink"]; - $item["plink"] = DI::httpClient()->finalUrl($item["plink"]); + try { + $item["plink"] = DI::httpClient()->finalUrl($item["plink"]); + } catch (TransferException $exception) { + Logger::notice('Item URL couldn\'t get expanded', ['url' => $item["plink"], 'exception' => $exception]); + } $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);