From fc4fe444ad62374f46aaa78dd0edaf6b218c487d Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Fri, 21 Jun 2024 14:31:55 +0200 Subject: [PATCH] Add custom rate limit deny handler This returns a proper JSON error for rate limit errors. The error handler was not enough. --- lib/transport/echo.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/transport/echo.go b/lib/transport/echo.go index 6b56d093..4f35276d 100644 --- a/lib/transport/echo.go +++ b/lib/transport/echo.go @@ -81,6 +81,10 @@ func CreateRateLimitMiddleware(requestsPerSecond int, burst int) echo.Middleware res := responses.TooManyRequestsError return context.JSON(res.HttpStatusCode, res) }, + DenyHandler: func(context echo.Context, identifier string,err error) error { + res := responses.TooManyRequestsError + return context.JSON(res.HttpStatusCode, res) + }, } return middleware.RateLimiterWithConfig(config)