]> git.mxchange.org Git - friendica.git/commitdiff
Catch exceptions for Worker::AddContact()
authorPhilipp <admin@philipp.info>
Wed, 18 May 2022 20:37:17 +0000 (22:37 +0200)
committerPhilipp <admin@philipp.info>
Wed, 18 May 2022 20:37:17 +0000 (22:37 +0200)
src/Worker/AddContact.php

index 0a9a71fb919cdb89647ec52ca9a1b3dcf7a40d57..1ac2b171e5d06145f933cff711ed5fda40617bfa 100644 (file)
 
 namespace Friendica\Worker;
 
-use Friendica\Core\Logger;
+use Friendica\DI;
 use Friendica\Model\Contact;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Network\HTTPException\NotFoundException;
 
 class AddContact
 {
@@ -33,14 +35,22 @@ class AddContact
         */
        public static function execute(int $uid, string $url)
        {
-               if ($uid == 0) {
-                       // Adding public contact
-                       $result = Contact::getIdForURL($url);
-                       Logger::info('Added public contact', ['url' => $url, 'result' => $result]);
-                       return;
-               }
+               try {
+                       if ($uid == 0) {
+                               // Adding public contact
+                               $result = Contact::getIdForURL($url);
+                               DI::logger()->info('Added public contact', ['url' => $url, 'result' => $result]);
+                               return;
+                       }
 
-               $result = Contact::createFromProbeForUser($uid, $url);
-               Logger::info('Added contact for user', ['uid' => $uid, 'url' => $url, 'result' => $result]);
+                       $result = Contact::createFromProbeForUser($uid, $url);
+                       DI::logger()->info('Added contact for user', ['uid' => $uid, 'url' => $url, 'result' => $result]);
+               } catch (InternalServerErrorException $e) {
+                       DI::logger()->warning('Internal server error.', ['exception' => $e, 'uid' => $uid, 'url' => $url]);
+               } catch (NotFoundException $e) {
+                       DI::logger()->notice('uid not found.', ['exception' => $e, 'uid' => $uid, 'url' => $url]);
+               } catch (\ImagickException $e) {
+                       DI::logger()->notice('Imagick not found.', ['exception' => $e, 'uid' => $uid, 'url' => $url]);
+               }
        }
 }