Skip to content

Commit cb3080a

Browse files
Merge pull request #2010 from timdeschryver/log-when-config-not-exists
feat: log when provided configId does not exist
2 parents b8e32c5 + fd6623b commit cb3080a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

projects/angular-auth-oidc-client/src/lib/config/config.service.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ describe('Configuration Service', () => {
120120

121121
spyOn(configService as any, 'loadConfigs').and.returnValue(of(configs));
122122
spyOn(configValidationService, 'validateConfig').and.returnValue(false);
123+
const consoleSpy = spyOn(console, 'warn');
123124

124125
configService.getOpenIDConfiguration('configId1').subscribe((config) => {
125126
expect(config).toBeNull();
127+
expect(consoleSpy).toHaveBeenCalledOnceWith(`[angular-auth-oidc-client] No configuration found for config id 'configId1'.`)
126128
});
127129
}));
128130

@@ -144,6 +146,7 @@ describe('Configuration Service', () => {
144146

145147
spyOn(configService as any, 'loadConfigs').and.returnValue(of(configs));
146148
spyOn(configValidationService, 'validateConfig').and.returnValue(true);
149+
const consoleSpy = spyOn(console, 'warn');
147150

148151
spyOn(storagePersistenceService, 'read').and.returnValue({
149152
issuer: 'auth-well-known',
@@ -153,6 +156,7 @@ describe('Configuration Service', () => {
153156
expect(config?.authWellknownEndpoints).toEqual({
154157
issuer: 'auth-well-known',
155158
});
159+
expect(consoleSpy).not.toHaveBeenCalled()
156160
});
157161
}));
158162

projects/angular-auth-oidc-client/src/lib/config/config.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, Injectable } from '@angular/core';
1+
import {inject, Injectable, isDevMode} from '@angular/core';
22
import { forkJoin, Observable, of } from 'rxjs';
33
import { concatMap, map } from 'rxjs/operators';
44
import { LoggerService } from '../logging/logger.service';
@@ -85,7 +85,13 @@ export class ConfigurationService {
8585

8686
private getConfig(configId?: string): OpenIdConfiguration | null {
8787
if (Boolean(configId)) {
88-
return this.configsInternal[configId as string] || null;
88+
const config = this.configsInternal[configId!];
89+
90+
if(!config && isDevMode()) {
91+
console.warn(`[angular-auth-oidc-client] No configuration found for config id '${configId}'.`);
92+
}
93+
94+
return config || null;
8995
}
9096

9197
const [, value] = Object.entries(this.configsInternal)[0] || [[null, null]];

0 commit comments

Comments
 (0)