]> git.mxchange.org Git - friendica.git/commitdiff
Add exception throw when contact data isn't available in Factory/Api/Mastodon/Relatio...
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 26 Mar 2023 22:30:31 +0000 (18:30 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 28 Mar 2023 01:31:53 +0000 (21:31 -0400)
- Address https://github.com/friendica/friendica/issues/12486#issuecomment-1445323023
- Remove default value to parameter which array keys are used in method body

src/Factory/Api/Mastodon/Relationship.php
src/Object/Api/Mastodon/Relationship.php

index f1ca4a1f9e6a245f0ff6532a925d8f30b3cc5822..8ae72ae9b2cd651df5d699e80eef9b56bac8f151 100644 (file)
@@ -22,6 +22,7 @@
 namespace Friendica\Factory\Api\Mastodon;
 
 use Exception;
+use Friendica\Network\HTTPException;
 use Friendica\Object\Api\Mastodon\Relationship as RelationshipEntity;
 use Friendica\BaseFactory;
 use Friendica\Model\Contact;
@@ -41,9 +42,15 @@ class Relationship extends BaseFactory
                $pcid  = !empty($cdata['public']) ? $cdata['public'] : $contactId;
                $cid   = !empty($cdata['user']) ? $cdata['user'] : $contactId;
 
+               $contact = Contact::getById($cid);
+               if (!$contact) {
+                       $this->logger->warning('Target contact not found', ['contactId' => $contactId, 'uid' => $uid, 'pcid' => $pcid, 'cid' => $cid]);
+                       throw new HTTPException\NotFoundException('Contact not found.');
+               }
+
                return new RelationshipEntity(
                        $pcid,
-                       Contact::getById($cid),
+                       $contact,
                        Contact\User::isBlocked($cid, $uid),
                        Contact\User::isIgnored($cid, $uid)
                );
index 42d0e73119bc315f6efccc7f99adec658ec50127..c042e81b5e3133ae548704cb3174db7b64c78d10 100644 (file)
@@ -77,7 +77,7 @@ class Relationship extends BaseDataTransferObject
         * @param bool  $blocked "true" if user is blocked
         * @param bool  $muted "true" if user is muted
         */
-       public function __construct(int $contactId, array $contactRecord = [], bool $blocked = false, bool $muted = false)
+       public function __construct(int $contactId, array $contactRecord, bool $blocked = false, bool $muted = false)
        {
                $this->id                   = (string)$contactId;
                $this->following            = false;