feat: SeededPodInitializer log exceptions as warning instead of crashing

This commit is contained in:
Pasini Luca
2023-02-01 18:50:33 +01:00
committed by Joachim Van Herwegen
parent 5acddcb5b2
commit 2efc141baa
2 changed files with 16 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { readJson } from 'fs-extra';
import type { RegistrationManager } from '../identity/interaction/email-password/util/RegistrationManager';
import { getLoggerFor } from '../logging/LogUtil';
import { createErrorMessage } from '../util/errors/ErrorUtil';
import { Initializer } from './Initializer';
/**
@@ -42,10 +43,15 @@ export class SeededPodInitializer extends Initializer {
this.logger.debug(`Validated input: ${JSON.stringify(validated)}`);
// Register and/or create a pod as requested. Potentially does nothing if all booleans are false.
await this.registrationManager.register(validated, true);
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
count += 1;
try {
await this.registrationManager.register(validated, true);
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
count += 1;
} catch (error: unknown) {
this.logger.warn(`Error while initializing seeded pod: ${createErrorMessage(error)})}`);
}
}
this.logger.info(`Initialized ${count} seeded pods.`);
}
}

View File

@@ -45,4 +45,11 @@ describe('A SeededPodInitializer', (): void => {
expect(registrationManager.validateInput).toHaveBeenCalledTimes(2);
expect(registrationManager.register).toHaveBeenCalledTimes(2);
});
it('does not throw exceptions when a seeded pod already exists.', async(): Promise<void> => {
registrationManager.register = jest.fn().mockRejectedValueOnce(new Error('Pod already exists'));
await new SeededPodInitializer(registrationManager, configFilePath).handle();
expect(registrationManager.validateInput).toHaveBeenCalledTimes(2);
expect(registrationManager.register).toHaveBeenCalledTimes(2);
});
});