Skip to content

🐛 [Bug]: limiter middleware does not count fiber.NewErrorf responses as failed when SkipSuccessfulRequests: true #3622

@lavish440

Description

@lavish440

Bug Description

When using the limiter middleware with SkipSuccessfulRequests: true and SkipFailedRequests: false, requests that return an error using fiber.NewErrorf(...) are not counted toward the rate limit.

How to Reproduce

  1. Run the app.
  2. Make a GET request to http://localhost:3000/.
  3. Observe the response is a 500 Internal Server Error.
  4. Repeat the request immediately.
  5. Notice that the request is not rate limited, even after exceeding the configured max (Max: 1).

Expected Behavior

Since the route returns a 500 status, and SkipFailedRequests is set to false, the request should be counted toward the rate limit.

After one such request, further requests within the expiration window (60s) should be rate limited.

Fiber Version

v3.0.0-beta.5.0.20250727145615-b839032cf299

Code Snippet (optional)

package main

import (
	"time"

	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/middleware/limiter"
)

func main() {
	app := fiber.New()

	app.Use(limiter.New(limiter.Config{
		Max:                    1,
		Expiration:             60 * time.Second,
		LimiterMiddleware:      limiter.SlidingWindow{},
		SkipSuccessfulRequests: true,
		SkipFailedRequests:     false,
		DisableHeaders:         true,
	}))

	app.Get("/", func(c fiber.Ctx) error {
		return fiber.NewErrorf(fiber.StatusInternalServerError, "Error")
	})

	app.Listen(":3000")
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions