mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: SeededPodInitializer log exceptions as warning instead of crashing
This commit is contained in:
committed by
Joachim Van Herwegen
parent
5acddcb5b2
commit
2efc141baa
@@ -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.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user