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.
This commit is contained in:
Sansan committed 2026-10-06 16:21:14 +02:00
1 parent bc7d406e41
commit 0ec2425f78
9 files changed
+67 -21

No files matched your search

+2 -2
View File
@@ -43,7 +43,7 @@ func parseLimit(ctx *echo.Context) (int32, bool) {
func withLimit[T any](ctx *echo.Context, name string, query func(*echo.Context, int32) (T, error)) error {
limit, ok := parseLimit(ctx)
if !ok {
return ctx.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid limit parameter"})
return echo.NewHTTPError(http.StatusBadRequest, "Invalid limit parameter")
}
result, err := query(ctx, limit)
return statsResult(ctx, name, result, err)
@@ -52,7 +52,7 @@ func withLimit[T any](ctx *echo.Context, name string, query func(*echo.Context,
func statsResult[T any](ctx *echo.Context, name string, result T, err error) error {
if err != nil {
logging.GetLogger().Error("Failed to get statistics", zap.String("statistic", name), zap.Error(err))
return ctx.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to get statistics"})
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to get statistics")
}
return ctx.JSON(http.StatusOK, result)
}