{"record":{"id":"6355116160ce93ff","repo":"yiisoft/yii2","slug":"rate-limit-exceeded","errorCode":null,"errorMessage":"Rate limit exceeded.","messagePattern":"Rate limit exceeded\\.","errorType":"http","errorClass":"TooManyRequestsHttpException","httpStatus":429,"severity":"error","filePath":"framework/filters/RateLimiter.php","lineNumber":142,"sourceCode":"     * @param Action $action the action to be executed\n     * @throws TooManyRequestsHttpException if rate limit exceeds\n     */\n    public function checkRateLimit($user, $request, $response, $action)\n    {\n        list($limit, $window) = $user->getRateLimit($request, $action);\n        list($allowance, $timestamp) = $user->loadAllowance($request, $action);\n\n        $current = time();\n\n        $allowance += (int) (($current - $timestamp) * $limit / $window);\n        if ($allowance > $limit) {\n            $allowance = $limit;\n        }\n\n        if ($allowance < 1) {\n            $user->saveAllowance($request, $action, 0, $current);\n            $this->addRateLimitHeaders($response, $limit, 0, $window);\n            throw new TooManyRequestsHttpException($this->errorMessage);\n        }\n\n        $user->saveAllowance($request, $action, $allowance - 1, $current);\n        $this->addRateLimitHeaders($response, $limit, $allowance - 1, (int) (($limit - $allowance + 1) * $window / $limit));\n    }\n\n    /**\n     * Adds the rate limit headers to the response.\n     * @param Response $response\n     * @param int $limit the maximum number of allowed requests during a period\n     * @param int $remaining the remaining number of allowed requests within the current period\n     * @param int $reset the number of seconds to wait before having maximum number of allowed requests again\n     */\n    public function addRateLimitHeaders($response, $limit, $remaining, $reset)\n    {\n        if ($this->enableRateLimitHeaders) {\n            $response->getHeaders()\n                ->set('X-Rate-Limit-Limit', $limit)","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/yiisoft/yii2/blob/66f00d18a29b520f85e8e8f1e32d1e7e7b556cac/framework/filters/RateLimiter.php#L124-L160","documentation":"Error \"Rate limit exceeded.\" thrown in yiisoft/yii2.","triggerScenarios":"Thrown at framework/filters/RateLimiter.php:142 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"66f00d18a29b520f85e8e8f1e32d1e7e7b556cac","analyzedAt":"2026-08-17T05:17:23.470Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}