mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-07 00:15:23 +02:00
⚡ perf: Separate Error Handling for Principal Resolution vs Config Overrides (#12550)
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:
parent
a100aa5738
commit
1729378a65
2 changed files with 23 additions and 5 deletions
|
|
@ -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')),
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue