[MM-24753] Improves error message when plugin crashes during slash command (#15334)

Co-authored-by: Ali Farooq <ali.farooq0@pm.me>
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
Ashim Sedhain
2020-10-02 03:02:58 -05:00
коммит произвёл GitHub
родитель 51d790300f
Коммит 2f47cf5994
5 изменённых файлов: 113 добавлений и 3 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package app
import (
"fmt"
"net/http"
"net/url"
"strings"
@@ -136,6 +137,11 @@ func (a *App) tryExecutePluginCommand(args *model.CommandArgs) (*model.Command,
return nil, nil, nil
}
// Checking if plugin is working or not
if err := pluginsEnvironment.PerformHealthCheck(matched.PluginId); err != nil {
return matched.Command, nil, model.NewAppError("ExecutePluginCommand", "model.plugin_command_error.error.app_error", map[string]interface{}{"Command": trigger}, "err= Plugin has recently crashed: "+matched.PluginId, http.StatusInternalServerError)
}
pluginHooks, err := pluginsEnvironment.HooksForPlugin(matched.PluginId)
if err != nil {
return matched.Command, nil, model.NewAppError("ExecutePluginCommand", "model.plugin_command.error.app_error", nil, "err="+err.Error(), http.StatusInternalServerError)
@@ -150,5 +156,11 @@ func (a *App) tryExecutePluginCommand(args *model.CommandArgs) (*model.Command,
}
response, appErr := pluginHooks.ExecuteCommand(a.PluginContext(), args)
// Checking if plugin crashed after running the command
if err := pluginsEnvironment.PerformHealthCheck(matched.PluginId); err != nil {
errMessage := fmt.Sprintf("err= Plugin %s crashed due to /%s command", matched.PluginId, trigger)
return matched.Command, nil, model.NewAppError("ExecutePluginCommand", "model.plugin_command_crash.error.app_error", map[string]interface{}{"Command": trigger, "PluginId": matched.PluginId}, errMessage, http.StatusInternalServerError)
}
return matched.Command, response, appErr
}