added import middleware
This commit is contained in:
@ -5,6 +5,7 @@ namespace App\Exceptions;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Http\Exceptions\ThrottleRequestsException;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
@ -127,6 +128,13 @@ class Handler extends ExceptionHandler
|
||||
return response()->view('errors.500', [], 500);
|
||||
}
|
||||
|
||||
if ($exception instanceof ThrottleRequestsException) {
|
||||
// ajax 500 json feedback
|
||||
if ($request->ajax()) {
|
||||
return response()->json(['error' => $exception->getMessage()], 429);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +113,10 @@ class Kernel extends HttpKernel
|
||||
'language',
|
||||
'firewall.all',
|
||||
],
|
||||
|
||||
'import' => [
|
||||
'throttle:import',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -116,6 +116,8 @@ class Route extends Provider
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
$this->mapInstallRoutes();
|
||||
|
||||
$this->mapApiRoutes();
|
||||
@ -157,8 +159,6 @@ class Route extends Provider
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
$this->configureRateLimiting();
|
||||
|
||||
Facade::prefix('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
@ -261,7 +261,11 @@ class Route extends Provider
|
||||
protected function configureRateLimiting()
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60);
|
||||
return Limit::perMinute(config('app.throttles.api'));
|
||||
});
|
||||
|
||||
RateLimiter::for('import', function (Request $request) {
|
||||
return Limit::perMinute(config('app.throttles.import'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user