Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion drivers/middleware/fasthttp/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fasthttp

import (
"log"

"github.com/valyala/fasthttp"
)

Expand All @@ -26,8 +28,13 @@ func WithErrorHandler(handler ErrorHandler) Option {
}

// DefaultErrorHandler is the default ErrorHandler used by a new Middleware.
// It logs the store error and responds with 503 so that store outages do not
// crash the request pipeline. Override via WithErrorHandler for custom behavior
// (e.g. fail-open).
func DefaultErrorHandler(ctx *fasthttp.RequestCtx, err error) {
panic(err)
log.Printf("limiter: store error: %v", err)
ctx.SetStatusCode(fasthttp.StatusServiceUnavailable)
ctx.Response.SetBodyString("Service Unavailable")
}

// LimitReachedHandler is an handler used to inform when the limit has exceeded.
Expand Down
7 changes: 6 additions & 1 deletion drivers/middleware/gin/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gin

import (
"log"
"net/http"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -28,8 +29,12 @@ func WithErrorHandler(handler ErrorHandler) Option {
}

// DefaultErrorHandler is the default ErrorHandler used by a new Middleware.
// It logs the store error and responds with 503 so that store outages do not
// crash the request pipeline. Override via WithErrorHandler for custom behavior
// (e.g. fail-open).
func DefaultErrorHandler(c *gin.Context, err error) {
panic(err)
log.Printf("limiter: store error: %v", err)
c.String(http.StatusServiceUnavailable, "Service Unavailable")
}

// LimitReachedHandler is an handler used to inform when the limit has exceeded.
Expand Down
7 changes: 6 additions & 1 deletion drivers/middleware/stdlib/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stdlib

import (
"log"
"net/http"

"github.com/ulule/limiter/v3"
Expand Down Expand Up @@ -28,8 +29,12 @@ func WithErrorHandler(handler ErrorHandler) Option {
}

// DefaultErrorHandler is the default ErrorHandler used by a new Middleware.
// It logs the store error and responds with 503 so that store outages do not
// crash the request pipeline. Override via WithErrorHandler for custom behavior
// (e.g. fail-open).
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error) {
panic(err)
log.Printf("limiter: store error: %v", err)
http.Error(w, "Service Unavailable", http.StatusServiceUnavailable)
}

// LimitReachedHandler is an handler used to inform when the limit has exceeded.
Expand Down