Catch TransferExceptions for HTTPClient::finalUrl() in case the headers are empty

This commit is contained in:
Philipp Holzer 2021-08-29 13:37:08 +02:00
parent e88c12d958
commit b76634ea0c
No known key found for this signature in database
GPG Key ID: 9A28B7D4FF5667BD
3 changed files with 11 additions and 3 deletions

View File

@ -220,7 +220,7 @@ class HTTPClient implements IHTTPClient
$urlResult = $this->resolver->resolveURL($url); $urlResult = $this->resolver->resolveURL($url);
if ($urlResult->didErrorOccur()) { if ($urlResult->didErrorOccur()) {
throw new TransferException($urlResult->getErrorMessageString()); throw new TransferException($urlResult->getErrorMessageString(), $urlResult->getHTTPStatusCode());
} }
return $urlResult->getURL(); return $urlResult->getURL();

View File

@ -21,6 +21,8 @@
namespace Friendica\Network; namespace Friendica\Network;
use GuzzleHttp\Exception\TransferException;
/** /**
* Interface for calling HTTP requests and returning their responses * Interface for calling HTTP requests and returning their responses
*/ */
@ -124,7 +126,8 @@ interface IHTTPClient
* @param string $url A user-submitted URL * @param string $url A user-submitted URL
* *
* @return string A canonical 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); public function finalUrl(string $url);
} }

View File

@ -42,6 +42,7 @@ use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
use GuzzleHttp\Exception\TransferException;
/** /**
* This class contain functions to import feeds (RSS/RDF/Atom) * This class contain functions to import feeds (RSS/RDF/Atom)
@ -297,7 +298,11 @@ class Feed
$orig_plink = $item["plink"]; $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); $item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);