0

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
  • 1
    In .env file are you sure APP_DEBUG is equal to true? Commented Oct 24, 2019 at 10:36
  • 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. Commented Oct 24, 2019 at 10:39
  • Please give code of app/Exceptions/Handler.php Commented Oct 24, 2019 at 10:42
  • Exceptions\Handler code added to question @SerhiiPosternak Commented Oct 24, 2019 at 10:55

4 Answers 4

2

File .env

APP_DEBUG=false

File config/app.php

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

Run command

php artisan config:cache
Sign up to request clarification or add additional context in comments.

1 Comment

I have those configurations the way you suggested @Nick
1

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

Comments

1

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.

1 Comment

I know that my controller is not created, I forced it to gerenate a internal server error. The problem is that the page instead of showing the generic message shows the exception message
0

Problem Solved!

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

Thanks for all the answers given so far

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.