fix: better test plugin error handling

Signed-off-by: lesion <lesion@autistici.org>
This commit is contained in:
lesion 2024-06-26 13:05:29 +02:00
parent 92bb516b33
commit e91659408b
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 14 additions and 7 deletions

View file

@ -66,18 +66,22 @@ export default {
computed: mapState(['settings']), computed: mapState(['settings']),
methods: { methods: {
...mapActions(['setSetting']), ...mapActions(['setSetting']),
async saveSettings() { async saveSettings(close=true) {
this.loading = true this.loading = true
await this.setSetting({ await this.setSetting({
key: 'plugin_' + this.selectedPlugin.name, key: 'plugin_' + this.selectedPlugin.name,
value: this.selectedPlugin.settingsValue value: this.selectedPlugin.settingsValue
}) })
this.loading = false this.loading = false
this.dialog = false if (close) {
this.dialog = false
}
}, },
async testPlugin() { async testPlugin() {
await this.saveSettings() await this.saveSettings(false)
this.$axios.$post(`/plugin/test/${this.selectedPlugin.name}`) this.$axios.$post(`/plugin/test/${this.selectedPlugin.name}`).catch( e => {
this.$root.$message(e?.response?.data?.message ?? e, { color: 'warning'})
})
}, },
toggleEnable(plugin) { toggleEnable(plugin) {
this.$axios.$put(`/plugin/${plugin.name}`) this.$axios.$put(`/plugin/${plugin.name}`)

View file

@ -62,19 +62,22 @@ const pluginController = {
return res.sendStatus(404) return res.sendStatus(404)
} }
await plugin.onTest() try {
await plugin.onTest()
} catch (response) {
return res.status(400).send({ message: String(response) })
}
res.sendStatus(200) res.sendStatus(200)
}, },
unloadPlugin(pluginName) { unloadPlugin(pluginName) {
const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName) const plugin = pluginController.plugins.find(p => p.configuration.name === pluginName)
const settings = settingsController.settings['plugin_' + pluginName]
if (!plugin) { if (!plugin) {
log.warn(`Plugin ${pluginName} not found`) log.warn(`Plugin ${pluginName} not found`)
return return
} }
const notifier = require('../../notifier') const notifier = require('../../notifier')
log.info('Unload plugin ' + plugin) log.info('Unload plugin ' + plugin.configuration.name)
if (typeof plugin.onEventCreate === 'function') { if (typeof plugin.onEventCreate === 'function') {
notifier.emitter.off('Create', plugin.onEventCreate) notifier.emitter.off('Create', plugin.onEventCreate)
} }