From 6372b20a0b79e5d261bc284fc34799dc665864f7 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 24 Oct 2024 19:36:35 -0300 Subject: [PATCH] feat(router,errors): BadRequest error --- lib/router/rerrors/400s.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/router/rerrors/400s.go b/lib/router/rerrors/400s.go index 4db7838..6463484 100644 --- a/lib/router/rerrors/400s.go +++ b/lib/router/rerrors/400s.go @@ -2,8 +2,21 @@ package rerrors import ( "net/http" + "strconv" ) +func BadRequest(reason ...string) RouteError { + info := map[string]any{} + + if len(reason) == 1 { + info["reason"] = reason[0] + } else if len(reason) > 1 { + for i, r := range reason { + info["reason_"+strconv.Itoa(i)] = r + } + } + + return NewRouteError(http.StatusBadRequest, "Bad Request", info) } func NotFound() RouteError {