mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
surround command instanciation with try-catch
This commit is contained in:
parent
4de64ea070
commit
7615d6efb1
@ -38,17 +38,24 @@ export class CommandFactory {
|
||||
}
|
||||
const CommandClass = this.commands.get(name);
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`createCommand() name=${name} commandClass=${CommandClass ? CommandClass.name : 'null'}`)
|
||||
methodLogger.debug(`createCommand() name=${name} commandClass=${CommandClass ? JSON.stringify(CommandClass) : 'null'}`)
|
||||
}
|
||||
if (!CommandClass) {
|
||||
const errmsg = `Command ${name} not found`;
|
||||
methodLogger.error(errmsg);
|
||||
throw new Error(errmsg);
|
||||
}
|
||||
const command = new CommandClass(params) as Command<T>;
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`createCommand() command=${JSON.stringify(command)}`)
|
||||
try {
|
||||
const command = new CommandClass(params) as Command<T>;
|
||||
if (methodLogger.isDebugEnabled()) {
|
||||
methodLogger.debug(`createCommand() command=${JSON.stringify(command)}`)
|
||||
}
|
||||
return command;
|
||||
} catch (error) {
|
||||
const errmsg = `Failed to create command ${name}: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
||||
methodLogger.error(errmsg);
|
||||
throw new Error(errmsg);
|
||||
}
|
||||
return command;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user