perf: Separate Error Handling for Principal Resolution vs Config Overrides (#12550)
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run

Distinguish between buildPrincipals and getApplicableConfigs failures
so the uncached fallback to baseConfig is intentional and logged
separately from config override errors.
This commit is contained in:
Danny Avila 2026-04-06 17:58:13 -04:00 committed by GitHub
parent a100aa5738
commit 1729378a65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 5 deletions

View file

@ -254,6 +254,18 @@ describe('createAppConfigService', () => {
expect(config).toEqual(deps._baseConfig);
});
it('falls back to base config on buildPrincipals error', async () => {
const deps = createDeps({
getUserPrincipals: jest.fn().mockRejectedValue(new Error('principal lookup failed')),
});
const { getAppConfig } = createAppConfigService(deps);
const config = await getAppConfig({ userId: 'uid1', role: 'USER' });
expect(deps.getApplicableConfigs).not.toHaveBeenCalled();
expect(config).toEqual(deps._baseConfig);
});
it('falls back to base config on getApplicableConfigs error', async () => {
const deps = createDeps({
getApplicableConfigs: jest.fn().mockRejectedValue(new Error('DB down')),

View file

@ -168,14 +168,20 @@ export function createAppConfigService(deps: AppConfigServiceDeps) {
}
}
let principals: Array<{ principalType: string; principalId?: string | Types.ObjectId }>;
try {
const principals = await buildPrincipals(role, userId);
principals = await buildPrincipals(role, userId);
} catch (error) {
logger.error('[getAppConfig] Error building principals, falling back to base:', error);
return baseConfig;
}
if (principals.length === 0) {
await cache.set(cacheKey, baseConfig, overrideCacheTtl);
return baseConfig;
}
if (principals.length === 0) {
await cache.set(cacheKey, baseConfig, overrideCacheTtl);
return baseConfig;
}
try {
const configs = await getApplicableConfigs(principals);
if (configs.length === 0) {