Skip to content

Commit

Permalink
Add custom rate limit deny handler
Browse files Browse the repository at this point in the history
This returns a proper JSON error for rate limit errors.
The error handler was not enough.
  • Loading branch information
bumi committed Jun 21, 2024
1 parent ed59850 commit fc4fe44
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/transport/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fc4fe44

Please sign in to comment.