I do not know why errors are not rendered in my project, it simply does not go through the handler method.
bootstrap / app.php
<?php
$app = new Illuminate\Foundation\Application(
realpath(__DIR__ . '/../')
);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
return $app;
app / Exception / Handler.php.php
namespace App\Exceptions;
use Exception;
use GrahamCampbell\Exceptions\ExceptionHandler as ExceptionHandler;
class Handler extends ExceptionHandler {
protected $dontReport = [
\Symfony\Component\HttpKernel\Exception\HttpException::class,
];
public function report(Exception $e) {
return parent::report($e);
}
public function render($request, Exception $e) {
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}
$whoops = new \Whoops\Run;
if ($request->ajax()) {
$whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
} else {
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
}
return new \Illuminate\Http\Response(
$whoops->handleException($e), $e->getStatusCode(), $e->getHeaders()
);
}
I have tried to do this in several ways, when the error is 404 and I put this snippet in the handler, it works:
if (method_exists($e, 'getStatusCode') && $e->getStatusCode() == 404)
return redirect('/erro');
return parent::render($request, $e);
But I'm trying to divide by 0 to force the error and by no means works in the first example, other errors that I've had during development are also not handled.