{"record":{"id":"ae0a945d3b5946a9","repo":"passbolt/passbolt_api","slug":"could-not-retrieve-the-user-key-policies","errorCode":null,"errorMessage":"Could not retrieve the user key policies.","messagePattern":"Could not retrieve the user key policies\\.","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltCe/UserKeyPolicies/src/Controller/UserKeyPoliciesGetSettingsController.php","lineNumber":64,"sourceCode":"    }\n\n    /**\n     * Returns user key policies settings.\n     *\n     * @return void\n     */\n    public function get(): void\n    {\n        $this->assertQueryParameters();\n\n        $userPassphraseGetSettingsService = new UserKeyPoliciesGetSettingsService();\n        try {\n            $userKeyPoliciesSettingsDto = $userPassphraseGetSettingsService->get();\n\n            $this->success(__('The operation was successful.'), $userKeyPoliciesSettingsDto->toArray());\n        } catch (Throwable $error) {\n            Log::error($error->getMessage());\n            throw new InternalErrorException(__('Could not retrieve the user key policies.'), null, $error);\n        }\n    }\n\n    /**\n     * This method verifies that a guest user can be authenticated with a valid user ID and authentication token.\n     *\n     * @return void\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException If the user is a guest and neither a user ID nor an authentication token is provided.\n     * @throws \\Cake\\Http\\Exception\\BadRequestException If the provided user ID is not a valid UUID.\n     * @throws \\Cake\\Http\\Exception\\BadRequestException If the provided authentication token is not a valid UUID.\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException If no valid authentication token is found.\n     */\n    private function assertQueryParameters(): void\n    {\n        $isLoggedIn = !$this->User->isGuest();\n        $isUserToken = $this->getRequest()->getQuery('user_id', false) || $this->getRequest()->getQuery('token', false);\n\n        if ($isLoggedIn) {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/UserKeyPolicies/src/Controller/UserKeyPoliciesGetSettingsController.php#L46-L82","documentation":"This InternalErrorException wraps any Throwable thrown while the UserKeyPoliciesGetSettingsController::get() action fetches the user key policy settings DTO. The controller logs the original message and rethrows a generic 500 so internal details are not leaked to the client. It indicates the settings service (e.g. organization settings lookup) failed unexpectedly, not a problem with the request itself.","triggerScenarios":"Calling GET /user-key-policies/settings when the underlying UserPassphraseGetSettingsService::get() throws — e.g. the organization settings row cannot be read from the database, the settings payload fails to decode, or any unexpected exception occurs inside the service.","commonSituations":"Database outages or migration drift leaving the organization settings table missing/corrupt; corrupted or invalid serialized settings; a plugin misconfiguration causing the service to throw during retrieval; the API response hides the root cause so the error log must be checked.","solutions":["Check the application error log for the 'Log::error' entry emitted by this controller — the original exception message identifies the root cause.","Run database migrations and verify the organization settings storage is intact (ddev refresh or equivalent migrate command).","Verify the UserKeyPolicies plugin is correctly enabled and its settings service dependencies are configured.","If the underlying error is transient (DB connection), retry the request after restoring database connectivity."],"exampleFix":"// before (server-side)\nthrow new InternalErrorException(__('Could not retrieve the user key policies.'), null, $error);\n// after (caller-side guard)\ntry {\n    $response = $http->get('/user-key-policies/settings.json');\n} catch (HttpException $e) {\n    if ($e->getCode() === 500) {\n        // inspect server logs for the wrapped root cause before retrying\n    }\n}","handlingStrategy":"try-catch","validationCode":"// No client-side validation; ensure connectivity beforehand\nif (!isReachable(apiBaseUrl)) { throw new Error('API unreachable'); }","typeGuard":null,"tryCatchPattern":"try {\n  const res = await api.get('/user-key-policies/settings.json');\n} catch (e) {\n  if (e.response && e.response.status === 500) {\n    // 500 is opaque: check server logs for the wrapped cause; retry only if transient\n  }\n}","preventionTips":["Keep database migrations current so settings storage exists.","Monitor server error logs — the API response masks the root cause.","Verify plugin settings configuration after upgrades."],"tags":["internal-error","http-500","settings-retrieval","php"],"backgroundTag":"internal-invariant-violation","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}