Checkpoint
Some checks failed
Test and build / Test and lint (push) Failing after 36s
Test and build / Build collector (push) Failing after 43s
Test and build / Build receiver (push) Failing after 42s

This commit is contained in:
2026-03-05 15:38:18 +01:00
parent 3106b2cf45
commit 13afa08e8a
108 changed files with 19509 additions and 729 deletions

30
server/error.go Normal file
View File

@@ -0,0 +1,30 @@
package server
import (
"net/http"
"os"
"github.com/labstack/echo/v4"
)
// apiError handles API errors consistently
func (s *Server) apiError(c echo.Context, err error, status ...int) error {
s.logger.Warnf("server: error serving %s %s: %v", c.Request().Method, c.Request().URL.Path, err)
if len(status) > 0 {
return c.JSON(status[0], map[string]any{
"error": err.Error(),
})
}
switch {
case os.IsNotExist(err):
return c.JSON(http.StatusNotFound, nil)
case os.IsPermission(err):
return c.JSON(http.StatusUnauthorized, nil)
default:
return c.JSON(http.StatusInternalServerError, map[string]any{
"error": err.Error(),
})
}
}