From b6429aa7cf6f93c488313747bf1884d54adfe1ce Mon Sep 17 00:00:00 2001 From: Wisp X Date: Sun, 20 Feb 2022 14:27:23 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=8E=A5=E5=8F=A3=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=99=90=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Exceptions/Handler.php | 5 +++++ resources/views/common/api.blade.php | 32 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index de731466..034fe84f 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -5,6 +5,7 @@ namespace App\Exceptions; use App\Http\Api; use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; +use Illuminate\Http\Exceptions\ThrottleRequestsException; use Throwable; class Handler extends ExceptionHandler @@ -41,6 +42,10 @@ class Handler extends ExceptionHandler $this->reportable(function (Throwable $e) { // }); + + $this->renderable(function (ThrottleRequestsException $e) { + return $this->error($e->getMessage())->setStatusCode(429); + }); } protected function unauthenticated($request, AuthenticationException $exception) diff --git a/resources/views/common/api.blade.php b/resources/views/common/api.blade.php index bc40bb31..f7df8533 100644 --- a/resources/views/common/api.blade.php +++ b/resources/views/common/api.blade.php @@ -18,6 +18,38 @@

如果未设置 Authorization 的情况下请求上传接口,将被视为游客上传。

+ +
+

公共响应 headers 说明

+ + + + + + + + + + + + + + + + + + + + +
+ 字段 + + 类型 + + 说明 +
X-RateLimit-LimitInteger当前客户端一分钟内请求配额
X-RateLimit-RemainingInteger当前客户端剩余请求配额
+

超出请求配额后,程序将会返回 HTTP 429 Too Many Requests 错误。

+

图片相关