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; }