Files
MusicServer/internal/server/middleware/sync_check.go
T
Sansan 0ec2425f78 Return every error as {"error": "..."}
Echo errors, middleware and handlers used three different formats (message object, error object, bare string). One error handler now writes all of them the same way; status codes are unchanged.
2026-10-06 16:21:14 +02:00

23 lines
542 B
Go

package middleware
import (
"net/http"
"music-server/internal/logging"
"github.com/labstack/echo/v5"
)
// SyncCheck blocks requests with HTTP 423 Locked while a sync is in progress.
func SyncCheck(isSyncing func() bool) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error {
if isSyncing() {
logging.GetLogger().Info("Syncing is in progress - request blocked")
return echo.NewHTTPError(http.StatusLocked, "Syncing is in progress")
}
return next(c)
}
}
}