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']),
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}`)

View file

@ -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)
}