package main import ( "errors" "net/http" "git.mchus.pro/mchus/quoteforge/internal/handlers" "github.com/gin-gonic/gin" ) // errCase maps a sentinel error to the HTTP status/message respondByErrCase // should use when errors.Is matches it. type errCase struct { err error status int message string } // respondByErrCase responds with the status/message of the first matching // case (checked in order), or a 500 "internal server error" fallback when // none match. Centralizes the switch-on-sentinel-error pattern repeated // across the config/project HTTP handlers in this file. func respondByErrCase(c *gin.Context, err error, cases ...errCase) { for _, cs := range cases { if errors.Is(err, cs.err) { handlers.RespondError(c, cs.status, cs.message, err) return } } handlers.RespondError(c, http.StatusInternalServerError, "internal server error", err) }