lokcon
lokcon

Reputation: 447

Laravel not displaying debug messages after adding custom error pages

I want my Laravel (4.2) site to return some custom error messages (instead of that Whoops, looks like something went wrong.) when errors occurred, so I added the following:

App::error(function(Exception $exception, $code)
{
    Log::error($exception);

    return Response::view('errors.500', [], 500);
});

use Illuminate\Database\Eloquent\ModelNotFoundException;
App::error(function(ModelNotFoundException $e)
{
    return Response::view('errors.404', [], 404);
});

to app/start/global.php

To test the pages I have temporarily changed: 'debug' => false in app/config/local/app.php

My custom error pages are displaying correctly (when errors occurred). However they are still displaying (instead of a error page with stack traces and error messages) even if I reverted my local development config back to 'debug' => true.

I tried to paste the following to app/start/local.php hoping it would override the global error handling when laravel is in a local environment. But that does not solve the problem.

App::error(function(Exception $exception, $code)
{
    Log::error($exception);
});

use Illuminate\Database\Eloquent\ModelNotFoundException;
App::error(function(ModelNotFoundException $e)
{
    Log::error($exception);    
});

How can I make laravel display error stack traces again?

Upvotes: 3

Views: 1755

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 152880

The problem is that as soon if you return something from an App::error handler, Laravel will use it as response and stop "bubbling up".

The easiest way is just to check with the app.debug config:

App::error(function(Exception $exception, $code)
{
    Log::error($exception);
    if(Config::get('app.debug') !== true){
        return Response::view('errors.500', [], 500);
    }
});

use Illuminate\Database\Eloquent\ModelNotFoundException;
App::error(function(ModelNotFoundException $e)
{
    if(Config::get('app.debug') !== true){
        return Response::view('errors.404', [], 404);
    }
});

Upvotes: 2

Related Questions