0

I think it's the most useless error message EVER.

"Whoops, looks like something went wrong."

Why can't it tell me what went wrong?

I already tried doing this but it still won't give me an error message.

I also tried adding this to the controller and view still nothing.

I also tried this in the app.php

'env' => env('APP_ENV', 'development'),
'debug' => env('APP_DEBUG', true),

I ended up doing die every line just to know what went wrong.

I checked the storage and no error logs just .gitignore

And what went wrong? Well, I was using an object variable as an array.

So why didn't it tell me that? But instead made me play a game of where's Waldo?

It does display helpful error messages "not always just like now"

Can anyone help me how to always display a helpful error message on Laravel?

magicianiam
  • 1,474
  • 7
  • 33
  • 70
  • Don't you have a laravel.log under the storage? And below that message it usually say something about what was wrong. Also you can see what was wrong looking into Console and see which script was faulty, Anyway Laravel 5.5 have much more friendly error screens – Radu Nov 12 '17 at 14:20
  • @Radu nothing useful there just .gitignore – magicianiam Nov 12 '17 at 14:21
  • Try to make it yourself and see if it's logging something ... I also edited my first comment. – Radu Nov 12 '17 at 14:24
  • @Radu I don't have CLI access on the hosted server so I can't do consoles. This time the error message was what I just posted nothing more. – magicianiam Nov 12 '17 at 14:34
  • Did you check `.env` file in project's root? Values there overwrite those in config/app.php. Especially check `APP_DEBUG` and `APP_LOG_LEVEL` entries in the file. – Matey Nov 12 '17 at 14:40
  • @magicianiam by console I mean the browser console .... like Inspect on Chrome and after that go to Console you can find there which scripts are giving error ad after click on it even the laravel error screen of course it's working especially on Ajax calls .... – Radu Nov 12 '17 at 14:46
  • Nothing on the console. Just that stupid error message of theirs inside HTML. – magicianiam Nov 12 '17 at 14:49
  • @Matey I'll go check that out. – magicianiam Nov 12 '17 at 14:49
  • Please keep us infomed :) – Radu Nov 12 '17 at 15:33

1 Answers1

1

First of all, to show error messages in detail you need to have enabled the app-debug in your .env file:
APP_LOG_LEVEL=debug


Now the interesting part.

Add this to your App\Exceptions\Handler.php before the last }:

/**
 * Create a Symfony response for the given exception.
 *
 * @param  \Exception  $e
 * @return mixed
 */
protected function convertExceptionToResponse(Exception $e)
{
    if (config('app.debug')) {
        $whoops = new \Whoops\Run;
        $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);

        return response()->make(
            $whoops->handleException($e),
            method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500,
            method_exists($e, 'getHeaders') ? $e->getHeaders() : []
        );
    }

    return parent::convertExceptionToResponse($e);
}

Source.

Kenny Horna
  • 13,485
  • 4
  • 44
  • 71