Error page 500 returned instead of Laravel error page

Asked

Viewed 851 times

0

I don’t know why errors aren’t rendered in my project, it just doesn’t 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 several ways, when the error is 404 and I put this excerpt in Handler, it works:

 if (method_exists($e, 'getStatusCode') && $e->getStatusCode() == 404)
      return redirect('/erro');
 return parent::render($request, $e);

However I am trying to divide by 0 to force the error and in no way works in the first example, other errors I’ve had during development are also not treated.

  • Original do Laravel

  • I’m just forcing to test, in fact no error is rendered...hehe

  • I actually want to render the error with "filp/Whoops", which I have just discovered is no longer native from Laravel 5.

  • Precisely, my problem is not with the 404 errors, this are treated well, I want to render the errors so I can debug...

  • https://camo.githubusercontent.com/31a4e1410e740fd0ccda128cbcab8723f45e7e73/687474703a2f2f692e696d6775722e636f6d2f305651706539362e706e67

  • Kenny I downloaded the Whoops and put in my Routes so to test Route::get('/others/blog/', function () {&#xA; abort(500);&#xA; return 'Olá';&#xA;}); and it worked... How is the test you are doing with error 500? Note that mine . env is like this APP_ENV=local&#xA;APP_DEBUG=true (another detail am using version 2.0, you are using 1.1?)

  • My . env is like this tmb, and the version is also 2.0

  • And how are you sending error 500? I did a test on the index so too: Route::get('/', function () { abort(500); return 'Olá'; }); and it worked.

  • I did a division by zero in an action...

  • I tried an abortion(500); but neither did I

  • I get it, you want to intercept the Exceptions, here it worked normal, how much your project weighs?

  • then... 10gb... = P

  • I tested here division by 0 and it worked: http://i.stack.Imgur.com/Ooxhn.png - I can only assume that it was some mistake of yours, call me in the chat Stack Overflow tomorrow.

Show 8 more comments

1 answer

1


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

bootstrap app.php

Of:

$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! =)

  • I believe that many can still go through this situation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.