0
votes

I have an laravel 5.7 application that when I deactivate debug mode the internal server error page keeps showing the exception message instead of the generic message "Whoops, something went wrong on our servers!".

enter image description here

Here is the code of Exception Handler:

    <?php

namespace App\Exceptions;

use Doctrine\DBAL\Query\QueryException;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        \Illuminate\Auth\AuthenticationException::class,
        \Illuminate\Auth\Access\AuthorizationException::class,
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
        \Illuminate\Session\TokenMismatchException::class,
        \Illuminate\Validation\ValidationException::class,
        \Illuminate\Database\QueryException::class,
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        return parent::render($request, $exception);
    }

    /**
     * Convert an authentication exception into an unauthenticated response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Illuminate\Auth\AuthenticationException  $exception
     * @return \Illuminate\Http\Response
     */
    protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        return redirect()->guest('login');
    }
}

I have no custom 500 error view and the Exception Handler is by default. Do anyone knows why this is happening?

Best Regards

4
In .env file are you sure APP_DEBUG is equal to true?Eyad Jaabo
APP_DEBUG is false and I don´t want the degub mode active. I just don´t want to user to see the exception's messages in frontend.Pedro Costa
Please give code of app/Exceptions/Handler.phpSerhii Posternak
Exceptions\Handler code added to question @SerhiiPosternakPedro Costa

4 Answers

2
votes

File .env

APP_DEBUG=false

File config/app.php

'debug' => env('APP_DEBUG', false),

Run command

php artisan config:cache
1
votes

You can do in app/Exceptions/Handler.php something like this:

if ($this->isHttpException($exception)) {

        if ($exception->getStatusCode() == 404) {
            return response()->view('partials.error' . '_404', [], 404);
        }

        if ($exception->getStatusCode() == 403) {
            return response()->view('partials.error' . '_403', [], 403);
        }
    }

    if ($exception instanceof QueryException) {
        abort(500);
    }

also, you could make the instanceof ErrorException to keep it more generic

1
votes

Well, we don't really have much to go on here. If I were to make a guess though, I will say it seems you're attempting to invoke a controller, AdsController, that you have not created yet. Confirm in your app/Http/Controllers directory that you have a file bearing the name AdsController.php

---Edits---

What you want to do is keep the APP_DEBUG set to false in your .env file in production. But in your development or offline environment, you will want that option set to true so as to provide you with the trusty detailed error message you are accustomed to getting.

0
votes

Problem Solved!

I ran a fresh install of composer and the exception message disappeared.

Thanks for all the answers given so far