Fixed: [calendar ms synchro] do not throw an error if we are not allowed

to get the default calendar
This commit is contained in:
Julien Fastré 2023-03-23 11:23:14 +01:00
parent efa475df0f
commit 4eb7d10e45
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -22,6 +22,7 @@ use Chill\MainBundle\Entity\User;
use DateTimeImmutable; use DateTimeImmutable;
use LogicException; use LogicException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
use function array_key_exists; use function array_key_exists;
@ -74,9 +75,18 @@ class MapCalendarToUser
public function getDefaultUserCalendar(string $idOrUserPrincipalName): ?array public function getDefaultUserCalendar(string $idOrUserPrincipalName): ?array
{ {
$value = $this->machineHttpClient->request('GET', "users/{$idOrUserPrincipalName}/calendars", [ try {
'query' => ['$filter' => 'isDefaultCalendar eq true'], $value = $this->machineHttpClient->request('GET', "users/{$idOrUserPrincipalName}/calendars", [
])->toArray()['value']; '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; return $value[0] ?? null;
} }