From: Philipp Date: Wed, 18 May 2022 20:37:17 +0000 (+0200) Subject: Catch exceptions for Worker::AddContact() X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c33611c484e2cf5a3c626566588e26a1d14e12c6;p=friendica.git Catch exceptions for Worker::AddContact() --- diff --git a/src/Worker/AddContact.php b/src/Worker/AddContact.php index 0a9a71fb91..1ac2b171e5 100644 --- a/src/Worker/AddContact.php +++ b/src/Worker/AddContact.php @@ -21,8 +21,10 @@ 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]); + } } }