Repository: gofiber/fiber
File: router.go (Go)

Code before:
			err = route.Handlers[0](c)
		}
		return match, err // Stop scanning the stack
	}

	// If c.Next() does not match, return 404
	err := NewError(StatusNotFound, "Cannot "+c.method+" "+html.EscapeString(c.pathOriginal))
	if !c.matched && app.methodExist(c) {
		// If no match, scan stack again if other methods match the request
		// Moved from app.handler because middleware may break the route chain
		err = ErrMethodNotAllowed
	}
	return false, err
}

func (app *App) defaultRequestHandler(rctx *fasthttp.RequestCtx) {
	// Acquire DefaultCtx from the pool
	ctx, ok := app.AcquireCtx(rctx).(*DefaultCtx)
	if !ok {
		panic(errors.New("requestHandler: failed to type-assert to *DefaultCtx"))
	}

	defer app.ReleaseCtx(ctx)

	// Check if the HTTP method is valid
	if ctx.methodINT == -1 {
		_ = ctx.SendStatus(StatusNotImplemented) //nolint:errcheck // Always return nil
		return
	}

	// Optional: Check flash messages
	rawHeaders := ctx.Request().Header.RawHeaders()
	if len(rawHeaders) > 0 && bytes.Contains(rawHeaders, []byte(FlashCookieName)) {
		ctx.Redirect().parseAndClearFlashMessages()
	}

	// Attempt to match a route and execute the chain
	_, err := app.next(ctx)
	if err != nil {
		if catch := ctx.App().ErrorHandler(ctx, err); catch != nil {
			_ = ctx.SendStatus(StatusInternalServerError) //nolint:errcheck // Always return nil
		}
		// TODO: Do we need to return here?
	}
}

func (app *App) customRequestHandler(rctx *fasthttp.RequestCtx) {
	// Acquire CustomCtx from the pool
	c, ok := app.AcquireCtx(rctx).(CustomCtx)
	if !ok {
		panic(errors.New("requestHandler: failed to type-assert to CustomCtx"))

Review comment (bug):
I may have introduced a bug here, I need to add a check to replace `app.methodInt()`

Code after:
			err = route.Handlers[0](c)
		}
		return match, err // Stop scanning the stack
	}

	// If c.Next() does not match, return 404
	err := NewError(StatusNotFound, "Cannot "+c.method+" "+html.EscapeString(c.pathOriginal))
	if !c.matched && app.methodExist(c) {
		// If no match, scan stack again if other methods match the request
		// Moved from app.handler because middleware may break the route chain
		err = ErrMethodNotAllowed
	}
	return false, err
}

func (app *App) defaultRequestHandler(rctx *fasthttp.RequestCtx) {
	// Acquire DefaultCtx from the pool
	ctx, ok := app.AcquireCtx(rctx).(*DefaultCtx)
	if !ok {
		panic(errors.New("requestHandler: failed to type-assert to *DefaultCtx"))
	}

	defer app.ReleaseCtx(ctx)

	// Check if the HTTP method is valid
	if ctx.methodINT == -1 {
		_ = ctx.SendStatus(StatusNotImplemented) //nolint:errcheck // Always return nil
		return
	}

	// Optional: Check flash messages
	rawHeaders := ctx.Request().Header.RawHeaders()
	if len(rawHeaders) > 0 && bytes.Contains(rawHeaders, []byte(FlashCookieName)) {
		ctx.Redirect().parseAndClearFlashMessages()
	}

	// Attempt to match a route and execute the chain
	_, err := app.next(ctx)
	if err != nil {
		if catch := ctx.App().ErrorHandler(ctx, err); catch != nil {
			_ = ctx.SendStatus(StatusInternalServerError) //nolint:errcheck // Always return nil
		}
		// TODO: Do we need to return here?
	}
}

func (app *App) customRequestHandler(rctx *fasthttp.RequestCtx) {
	// Acquire CustomCtx from the pool
	ctx, ok := app.AcquireCtx(rctx).(CustomCtx)
	if !ok {
		panic(errors.New("requestHandler: failed to type-assert to CustomCtx"))