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-Limit | +Integer | +当前客户端一分钟内请求配额 | +
| X-RateLimit-Remaining | +Integer | +当前客户端剩余请求配额 | +
超出请求配额后,程序将会返回 HTTP 429 Too Many Requests 错误。
+图片相关