From 8dd53157758a57c6bd8a3ae3ca1de8d5fdd4843b Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Sat, 2 Mar 2019 10:07:14 +0100 Subject: [PATCH] handle error for local plugin --- src/app/components/local-plugin.js | 14 +++++++++++--- src/app/components/plugin-manager-component.js | 14 +++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/app/components/local-plugin.js b/src/app/components/local-plugin.js index de15d13f0a..5fc4ab2936 100644 --- a/src/app/components/local-plugin.js +++ b/src/app/components/local-plugin.js @@ -12,8 +12,16 @@ module.exports = class LocalPlugin { open (plugins) { this.profile = JSON.parse(localStorage.getItem('plugins/local')) || { notifications: {} } return new Promise((resolve, reject) => { + const onValidation = () => { + try { + const profile = this.create() + resolve(profile) + } catch (err) { + reject(err) + } + } modalDialog('Local Plugin', this.form(plugins), - { fn: () => resolve(this.create()) }, + { fn: () => onValidation() }, { fn: () => resolve() } ) }) @@ -94,7 +102,7 @@ module.exports = class LocalPlugin { return yo`
- +
@@ -102,7 +110,7 @@ module.exports = class LocalPlugin {
- +
diff --git a/src/app/components/plugin-manager-component.js b/src/app/components/plugin-manager-component.js index 72a125e5f0..5085881301 100644 --- a/src/app/components/plugin-manager-component.js +++ b/src/app/components/plugin-manager-component.js @@ -104,11 +104,15 @@ class PluginManagerComponent { * Add a local plugin to the list of plugins */ async openLocalPlugin () { - const profile = await this.localPlugin.open(this.store.getAll()) - if (!profile) return - const resolveLocaton = (iframe) => this.appManager.resolveLocation(profile, iframe) - const api = new Plugin(profile, { resolveLocaton }) - this.appManager.init([{profile, api}]) + try { + const profile = await this.localPlugin.open(this.store.getAll()) + if (!profile) return + const resolveLocaton = (iframe) => this.appManager.resolveLocation(profile, iframe) + const api = new Plugin(profile, { resolveLocaton }) + this.appManager.init([{profile, api}]) + } catch (err) { + console.log(`Cannot create Plugin : ${err.message}`) + } } render () {