Skip to content

Commit

Permalink
fix: fixes issue 1444 invoking the onPluginInit
Browse files Browse the repository at this point in the history
In api server the instantiatePlugin function is now calling the required
onPluginInit for each corresponding connector

Closes: hyperledger-cacti#1444
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
  • Loading branch information
m-courtin authored and RafaelAPB committed Nov 19, 2021
1 parent 40fe07f commit 2c777f7
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/cactus-cmd-api-server/src/main/typescript/api-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ export class ApiServer {
const pluginFactory = await createPluginFactory(pluginFactoryOptions);

const plugin = await pluginFactory.create(pluginOptions);

// need to invoke the i-cactus-plugin onPluginInit functionality here before plugin registry can be used further
try {
await plugin.onPluginInit();
} catch (error) {
const fnTag = `${this.className}#instantiatePlugin`;
const packageName = plugin.getPackageName();
const instanceId = plugin.getInstanceId();

const errorMessage = `${fnTag} failed calling onPluginInit() on the plugin '${packageName}' with the instanceId '${instanceId}'`;

this.log.error(errorMessage, error);

if (error instanceof Error) {
throw new RuntimeError(errorMessage, error);
} else {
throw new RuntimeError(errorMessage, JSON.stringify(error));
}
}

return plugin;
}

Expand Down

0 comments on commit 2c777f7

Please sign in to comment.