]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/HTTPSignature.php
Changes:
[friendica.git] / src / Util / HTTPSignature.php
index f082fe32f79f7eb3f9f905a2f6bca2d22050b28e..01f75776f2c23f5e5f305673e798d821a4d2d429 100644 (file)
@@ -1,6 +1,6 @@
 <?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
  *
@@ -420,19 +420,25 @@ class HTTPSignature
         * @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 [];
                }
@@ -446,7 +452,7 @@ class HTTPSignature
         * @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
@@ -622,7 +628,7 @@ class HTTPSignature
                }
 
                if (empty($algorithm)) {
-                       Logger::info('No alagorithm');
+                       Logger::info('No algorithm');
                        return false;
                }