From e91659408b98517316593bebd0b796d618f7a336 Mon Sep 17 00:00:00 2001 From: lesion Date: Wed, 26 Jun 2024 13:05:29 +0200 Subject: [PATCH] fix: better test plugin error handling Signed-off-by: lesion --- components/admin/Plugin.vue | 12 ++++++++---- server/api/controller/plugins.js | 9 ++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/admin/Plugin.vue b/components/admin/Plugin.vue index 6f51d7f5..60042c04 100644 --- a/components/admin/Plugin.vue +++ b/components/admin/Plugin.vue @@ -66,18 +66,22 @@ export default { computed: mapState(['settings']), methods: { ...mapActions(['setSetting']), - async saveSettings() { + async saveSettings(close=true) { this.loading = true await this.setSetting({ key: 'plugin_' + this.selectedPlugin.name, value: this.selectedPlugin.settingsValue }) this.loading = false - this.dialog = false + if (close) { + this.dialog = false + } }, async testPlugin() { - await this.saveSettings() - this.$axios.$post(`/plugin/test/${this.selectedPlugin.name}`) + await this.saveSettings(false) + this.$axios.$post(`/plugin/test/${this.selectedPlugin.name}`).catch( e => { + this.$root.$message(e?.response?.data?.message ?? e, { color: 'warning'}) + }) }, toggleEnable(plugin) { this.$axios.$put(`/plugin/${plugin.name}`) diff --git a/server/api/controller/plugins.js b/server/api/controller/plugins.js index d34aacfa..95cb1ecd 100644 --- a/server/api/controller/plugins.js +++ b/server/api/controller/plugins.js @@ -62,19 +62,22 @@ const pluginController = { return res.sendStatus(404) } - await plugin.onTest() + try { + await plugin.onTest() + } catch (response) { + return res.status(400).send({ message: String(response) }) + } res.sendStatus(200) }, unloadPlugin(pluginName) { const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName) - const settings = settingsController.settings['plugin_' + pluginName] if (!plugin) { log.warn(`Plugin ${pluginName} not found`) return } const notifier = require('../../notifier') - log.info('Unload plugin ' + plugin) + log.info('Unload plugin ' + plugin.configuration.name) if (typeof plugin.onEventCreate === 'function') { notifier.emitter.off('Create', plugin.onEventCreate) }