Error page 500 returned instead of Laravel error page

0

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.

    
asked by anonymous 02.03.2016 / 18:12

1 answer

0

I was able to solve the problem, a user from another forum suggested that because Laravel 5 is still not stable (about 7 months before now), I should have made the following change:

bootstrap \ app.php

From:

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

To:

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    Illuminate\Foundation\Exceptions\Handler::class
);

Problem solved! =)

    
07.03.2016 / 12:49