Routes NotFoundHttpException How can you handle route errors for curious users who could inject other non-existent routes and generate errors, and not show error screenshot but direct or control this error of non-existent routes?
for example:
http://localhost/kdjlkdjgdjgkdjgldjldgjdlgjdk
Symfony\Component\HttpKernel\Exception
NotFoundHttpException
in /var/www/html/ws/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php (line 230)
If your APP_DEBUG is false in the .env file, then you will not see that particular view; you will get a more generic view instead.
Additionally, you can handle the Symfony\Component\HttpKernel\Exception\NotFoundHttpException exception in app/Exceptions/Handler.php:
public function render($request, Throwable $exception)
{
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
if ($request->wantsJson()) {
return response()->json(['message' => 'No way José'], 404);
}
return redirect('/');
}
return parent::render($request, $exception);
}
turned out, that was it, thank you very much
It remained like this:
public function render($request, Throwable $exception)
{
if ($exception instanceof NotFoundHttpException) {
return response()->json(['message' => 'Not Found'], 404);
}
return parent::render($request, $exception);
}
Please sign in or create an account to participate in this conversation.