Mike Rockétt
Mike Rockétt

Reputation: 9007

Change "Whoops, looks like something went wrong." message

I'm sure I'm missing something silly here. I'm trying to replace the non-debug error screen that Laravel throws when there's an exception. It seems to be ignoring the code below (placed in start/global.php):

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

Why would it ignore that? And was I supposed to do something elsewhere as well?

Bit of clarity:

I'm testing this with a QueryException (HY000). But surely this should not make a difference?

Using Laravel 4.2

Upvotes: 4

Views: 8905

Answers (2)

Alana Storm
Alana Storm

Reputation: 166106

It'd be hard to say without seeing your system, but my first guess would be there's another call to App:error made after yours that overrides what's you're trying to do in app/global.php.

I just wrote about how Laravel sets up it's error handling recently. After reading that article (or maybe skipping it and diving in), the way I'd debug this would be to hop into

vendor/laravel/framework/src/Illuminate/Exception/Handler.php

and look at the definition of callCustomHandlers. This is the method that calls any handlers setup via App:error

protected function callCustomHandlers($exception, $fromConsole = false)
{
    foreach ($this->handlers as $handler)
    {
        //...
    }
}

Your handler will be in the $this->handlers array. I'd add some temporary debugging code to this class (the class may be in Laravel's single combined optimized file) to determine

  1. If your handler fails the handlesException test

  2. If there's another handler added to the queue after your that "wins" and sends a response.

It also never hurts to start with a

App::error(function()
{
    exit(__FILE__);
});

and then build out your error handler until it stops being called. That way you know what part of it Laravel's having a problem with.

Upvotes: 2

user1669496
user1669496

Reputation: 33078

In app/global.php there is a default error handler setup. You will want to remove that to use yours, or just modify that one.

Check this out for more information... http://laravel.com/docs/errors#handling-errors

Upvotes: 1

Related Questions