From ad63305fdff10460562c162903b6f16b257c0b9d Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Wed, 4 Sep 2019 14:54:04 +0000 Subject: [PATCH] Extract method in PluginReader to handle missing plugin resource Signed-off-by: Mykola Morhun --- .../plugin-ext/src/hosted/node/plugin-reader.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/plugin-ext/src/hosted/node/plugin-reader.ts b/packages/plugin-ext/src/hosted/node/plugin-reader.ts index 6dfde97d7e820..d1611818605da 100644 --- a/packages/plugin-ext/src/hosted/node/plugin-reader.ts +++ b/packages/plugin-ext/src/hosted/node/plugin-reader.ts @@ -39,12 +39,12 @@ export class HostedPluginReader implements BackendApplicationContribution { @multiInject(MetadataProcessor) private readonly metadataProcessors: MetadataProcessor[]; /** - * Map between a plugin's id and the local storage + * Map between a plugin id and its local storage */ - private pluginsIdsFiles: Map = new Map(); + protected pluginsIdsFiles: Map = new Map(); configure(app: express.Application): void { - app.get('/hostedPlugin/:pluginId/:path(*)', (req, res) => { + app.get('/hostedPlugin/:pluginId/:path(*)', async (req, res) => { const pluginId = req.params.pluginId; const filePath = req.params.path; @@ -67,11 +67,16 @@ export class HostedPluginReader implements BackendApplicationContribution { } }); } else { - res.status(404).send(`The plugin with id '${escape_html(pluginId)}' does not exist.`); + await this.handleMissingResource(req, res); } }); } + protected async handleMissingResource(req: express.Request, res: express.Response): Promise { + const pluginId = req.params.pluginId; + res.status(404).send(`The plugin with id '${escape_html(pluginId)}' does not exist.`); + } + async getPluginMetadata(pluginPath: string): Promise { return this.doGetPluginMetadata(pluginPath); }