diff --git a/lib/Service/OpenAiAPIService.php b/lib/Service/OpenAiAPIService.php index a7652aec..aafcecbd 100644 --- a/lib/Service/OpenAiAPIService.php +++ b/lib/Service/OpenAiAPIService.php @@ -55,7 +55,7 @@ public function __construct( } /** - * @param string $userId + * @param string $userId It can be an empty string * @param int $type * @param int $usage * @throws Exception If there is an error creating the quota usage. diff --git a/lib/Service/QuotaRuleService.php b/lib/Service/QuotaRuleService.php index 530170f1..ddf813a1 100644 --- a/lib/Service/QuotaRuleService.php +++ b/lib/Service/QuotaRuleService.php @@ -34,11 +34,12 @@ public function __construct( private LoggerInterface $logger, ) { } + /** * Returns the quota rule for the given user * * @param int $quotaType - * @param string $userId + * @param string $userId It can be an empty string * @return array */ public function getRule(int $quotaType, string $userId) { @@ -46,9 +47,13 @@ public function getRule(int $quotaType, string $userId) { $cacheKey = Application::QUOTA_RULES_CACHE_PREFIX . $quotaType . '-' . $userId; $rule = $cache->get($cacheKey); if ($rule === null) { - $user = $this->userManager->get($userId); - $groups = $this->groupManager->getUserGroupIds($user); try { + $user = $this->userManager->get($userId); + if ($user === null) { + // re-use the db exception for not found users + throw new DoesNotExistException('User not found: ' . $userId); + } + $groups = $this->groupManager->getUserGroupIds($user); $rule = $this->quotaRuleMapper->getRule($quotaType, $userId, $groups)->jsonSerialize(); } catch (DoesNotExistException|MultipleObjectsReturnedException) { $rule = [