flarum/framework · error · BadRequestException

page[limit] must be at least 1

Error message

page[limit] must be at least 1

What it means

Guard in RequestUtil::extractLimit: after falling back to the default limit and clamping to the optional maximum, a page[limit] value resolving to less than 1 (typically an explicit page[limit]=0 or a negative number) is invalid for pagination, so a 400 BadRequestException is thrown. A missing/empty limit returns null instead; only a genuinely non-positive requested limit hits this guard.

Solutions

  1. Request page[limit] >= 1
  2. Omit page[limit] entirely to use the endpoint's default limit
  3. Fix client code that computes the limit (e.g. pageSize 0) before calling the API
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at framework/core/src/Http/RequestUtil.php:171 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of flarum/framework@4b939f6853 (2026-09-15). Data as JSON: /api/errors/c0d17ca5e2bba810. Report an issue: GitHub.

Appendix: source

Thrown at framework/core/src/Http/RequestUtil.php:171

        if (! filled($limit)) {
            $limit = $defaultLimit;
        }

        // Only short-circuit when there is genuinely no limit (no page[limit] and no
        // default). A loose `! $limit` check here also caught the string "0", returning
        // null which then broke OffsetPagination's non-nullable int $limit. An explicit
        // page[limit]=0 must instead fall through to the `< 1` guard below and 400.
        if ($limit === null) {
            return null;
        }

        if ($max !== null) {
            $limit = min($limit, $max);
        }

        if ($limit < 1) {
            throw new BadRequestException('page[limit] must be at least 1');
        }

        return $limit;
    }

    public static function extractOffsetFromNumber(Request $request, int $limit): int
    {
        $page = (int) ($request->getQueryParams()['page']['number'] ?? 1);

        if ($page < 1) {
            throw new BadRequestException('page[number] must be at least 1');
        }

        return ($page - 1) * $limit;
    }

    public static function extractOffset(Request $request, ?int $limit = 0): int
    {

View on GitHub (pinned to 4b939f6853)