私はLaravel 5.5を使用しています。メソッド名とクラスThrowableを実装していないオブジェクトを投げることはできません
を以下のベンダー\ laravelの\枠組み\ SRC \を照らし\ルーティング\ミドルウェア\ ThrottleRequests.php
があります:と、BuildException
は、In、Laravel 5.4は、私ができました以下のようにこのメソッドでJSONを返します。
protected function buildException($key, $maxAttempts)
{
$retryAfter = $this->getTimeUntilNextRetry($key);
$headers = $this->getHeaders(
$maxAttempts,
$this->calculateRemainingAttempts($key, $maxAttempts, $retryAfter),
$retryAfter
);
return response()->json('429 Too many requests');
}
私はLaravel 5.5を使用して上記の方法でJSONを返すようにしようとすると、それは
今すぐ確認してください、どのように私はJSONを返すことができたThrowable
を実装していないオブジェクトを投げることができないと言います上記の方法のためのLaravel 5.5で
両方の場所(ThrottleRequestsとHandler.php)の両方でYourCustomExceptionの例を詳しく説明してください。 – Pankaj
'Symfony \ Component \ HttpKernel \ Exception \ HttpException'を拡張するカスタムクラスを' buildException'メソッドで作成できますハンドラでは 'if($ e instanceof YourCustomException){' –