Skip to content

Commit

Permalink
Merge pull request #2010 from timdeschryver/log-when-config-not-exists
Browse files Browse the repository at this point in the history
feat: log when provided configId does not exist
  • Loading branch information
FabianGosebrink authored Sep 21, 2024
2 parents b8e32c5 + fd6623b commit cb3080a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ describe('Configuration Service', () => {

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

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

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

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

spyOn(storagePersistenceService, 'read').and.returnValue({
issuer: 'auth-well-known',
Expand All @@ -153,6 +156,7 @@ describe('Configuration Service', () => {
expect(config?.authWellknownEndpoints).toEqual({
issuer: 'auth-well-known',
});
expect(consoleSpy).not.toHaveBeenCalled()
});
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, Injectable } from '@angular/core';
import {inject, Injectable, isDevMode} from '@angular/core';
import { forkJoin, Observable, of } from 'rxjs';
import { concatMap, map } from 'rxjs/operators';
import { LoggerService } from '../logging/logger.service';
Expand Down Expand Up @@ -85,7 +85,13 @@ export class ConfigurationService {

private getConfig(configId?: string): OpenIdConfiguration | null {
if (Boolean(configId)) {
return this.configsInternal[configId as string] || null;
const config = this.configsInternal[configId!];

if(!config && isDevMode()) {
console.warn(`[angular-auth-oidc-client] No configuration found for config id '${configId}'.`);
}

return config || null;
}

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

0 comments on commit cb3080a

Please sign in to comment.