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.
23 lines
542 B
Go
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)
|
|
}
|
|
}
|
|
}
|