fix: show proper error in the UI when enabling a plugin fails

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan 2026-01-03 18:31:36 -05:00
parent 5f54944366
commit 801466445d
2 changed files with 13 additions and 3 deletions

View File

@ -96,8 +96,8 @@ func (api *Router) updatePlugin(w http.ResponseWriter, r *http.Request) {
// Handle enable/disable
if req.Enabled != nil {
if *req.Enabled {
if err := api.pluginManager.EnablePlugin(ctx, id); err != nil {
log.Error(ctx, "Error enabling plugin", "id", id, err)
if enableErr := api.pluginManager.EnablePlugin(ctx, id); enableErr != nil {
log.Error(ctx, "Error enabling plugin", "id", id, enableErr)
// Refresh plugin from DB to get the error
plugin, err := repo.Get(id)
if err != nil {
@ -105,9 +105,18 @@ func (api *Router) updatePlugin(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
// Return error response with message field for React-Admin compatibility
// and include the plugin data so UI can update its state
errorResponse := struct {
Message string `json:"message"`
Plugin *model.Plugin `json:"plugin"`
}{
Message: enableErr.Error(),
Plugin: plugin,
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnprocessableEntity)
_ = json.NewEncoder(w).Encode(plugin)
_ = json.NewEncoder(w).Encode(errorResponse)
return
}
} else {

View File

@ -62,6 +62,7 @@ const ToggleEnabledSwitch = ({
)
},
onFailure: (error) => {
refresh()
notify(
error?.message || 'resources.plugin.notifications.error',
'warning',