mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
fix: show proper error in the UI when enabling a plugin fails
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
5f54944366
commit
801466445d
@ -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 {
|
||||
|
||||
@ -62,6 +62,7 @@ const ToggleEnabledSwitch = ({
|
||||
)
|
||||
},
|
||||
onFailure: (error) => {
|
||||
refresh()
|
||||
notify(
|
||||
error?.message || 'resources.plugin.notifications.error',
|
||||
'warning',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user