Laravel 5 Error Handling

I am using Laravel 5 and I am trying to set up custom 404 handling and custom exception handling, but I cannot figure out where to put my code. Some time ago an ErrorServiceProvider appeared which no longer exists. Can anyone give me some pointers?

EDIT: I saw that they added a Handler class to the App / Exception folder, but that still seems to be the wrong place to put it because it doesn't match at all laravel 4.2 App :: error, App :: missing and App :: fatal methods ... Does anyone have any idea?

+3


source to share


2 answers


Use app / Exceptions / Handler.php method to achieve this. L5 documentation http://laravel.com/docs/5.0/errors#handling-errors



public function render($request, Exception $e)
{
    if ($e instanceof Error) {
        if ($request->ajax()) {
            return response(['error' => $e->getMessage()], 400);
        } else {
            return $e->getMessage();
        }
    }

    if ($this->isHttpException($e)) {
        return $this->renderHttpException($e);
    } else {
        return parent::render($request, $e);
    }
}

      

+1


source


Here's how to customize the error page respecting the setting APP_DEBUG

in .env

.

app / exceptions / handler.php



public function render($request, Exception $e)
{
    if ($this->isHttpException($e))
    {
        return $this->renderHttpException($e);
    }
    else
    {
        if (env('APP_DEBUG'))
        {
            return parent::render($request, $e);
        }
        return response()->view('errors.500', [], 500);
    }
}

      

+1


source







All Articles