From 4eb7d10e459b4dd5b99d288f08132a63c5a716e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 23 Mar 2023 11:23:14 +0100 Subject: [PATCH] Fixed: [calendar ms synchro] do not throw an error if we are not allowed to get the default calendar --- .../Connector/MSGraph/MapCalendarToUser.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/RemoteCalendar/Connector/MSGraph/MapCalendarToUser.php b/src/Bundle/ChillCalendarBundle/RemoteCalendar/Connector/MSGraph/MapCalendarToUser.php index 504d48ffc..563bd3a38 100644 --- a/src/Bundle/ChillCalendarBundle/RemoteCalendar/Connector/MSGraph/MapCalendarToUser.php +++ b/src/Bundle/ChillCalendarBundle/RemoteCalendar/Connector/MSGraph/MapCalendarToUser.php @@ -22,6 +22,7 @@ use Chill\MainBundle\Entity\User; use DateTimeImmutable; use LogicException; use Psr\Log\LoggerInterface; +use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use function array_key_exists; @@ -74,9 +75,18 @@ class MapCalendarToUser public function getDefaultUserCalendar(string $idOrUserPrincipalName): ?array { - $value = $this->machineHttpClient->request('GET', "users/{$idOrUserPrincipalName}/calendars", [ - 'query' => ['$filter' => 'isDefaultCalendar eq true'], - ])->toArray()['value']; + try { + $value = $this->machineHttpClient->request('GET', "users/{$idOrUserPrincipalName}/calendars", [ + 'query' => ['$filter' => 'isDefaultCalendar eq true'], + ])->toArray()['value']; + } catch (ClientExceptionInterface $e) { + $this->logger->error('[MapCalendarToUser] Error while listing calendars for a user', [ + 'http_status_code' => $e->getResponse()->getStatusCode(), + 'id_user' => $idOrUserPrincipalName, + ]); + + return null; + } return $value[0] ?? null; }