<?php
/**
- * @copyright Copyright (C) 2010-2023, the Friendica project
+ * @copyright Copyright (C) 2010-2024, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* @return array JSON array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function fetch(string $request, int $uid): array
+ public static function fetch(string $request, int $uid = 0): array
{
- $curlResult = self::fetchRaw($request, $uid);
+ try {
+ $curlResult = self::fetchRaw($request, $uid);
+ } catch (\Exception $exception) {
+ Logger::notice('Error fetching url', ['url' => $request, 'exception' => $exception]);
+ return [];
+ }
if (empty($curlResult)) {
return [];
}
- if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
+ if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
+ Logger::debug('Fetching was unsuccessful', ['url' => $request, 'return-code' => $curlResult->getReturnCode(), 'error-number' => $curlResult->getErrorNumber(), 'error' => $curlResult->getError()]);
return [];
}
- $content = json_decode($curlResult->getBody(), true);
+ $content = json_decode($curlResult->getBodyString(), true);
if (empty($content) || !is_array($content)) {
return [];
}
* @param string $request request url
* @param integer $uid User id of the requester
* @param boolean $binary TRUE if asked to return binary results (file download) (default is "false")
- * @param array $opts (optional parameters) assoziative array with:
+ * @param array $opts (optional parameters) associative array with:
* 'accept_content' => supply Accept: header with 'accept_content' as the value
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'nobody' => only return the header
}
if (empty($algorithm)) {
- Logger::info('No alagorithm');
+ Logger::info('No algorithm');
return false;
}