Chamod Wijesena
Chamod Wijesena

Reputation: 168

Need to Handle Laravel Exception and, Logging details mismatch error

I have tried to handle the exceptions on Handler class in my laravel project

            if(!env('APP_DEBUG', false)){
                return view('errors.500');
            } else {
                return parent::render($request, $exception);
            }

Errors are redirecting to my page. but in the login page user name or password mismatch also redirecting to that page.

in the login error need to redirect to the login page,not to the common error page. how can handle it?

i have using default laravel auth login.

this is my Handler.php file,

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @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)
    {
        // Render well-known exceptions here

        // Otherwise display internal error message
        if(!env('APP_DEBUG', false)){
            return view('errors.500');
        } else {
            return parent::render($request, $exception);
        }
    }
}

Upvotes: 0

Views: 458

Answers (1)

John Lobo
John Lobo

Reputation: 15319

no need to check for 500 errors manually .If you want to show custom error message for 500 erorrs in production then publish default laravel views for errors

php artisan vendor:publish --tag=laravel-errors

This will generate views for errors in following path

resources/views/errors

To customize 500 erorrs .Edit following path

resources/views/errors/500.blade.php

Also make sure this will only show when

APP_DEBUG=false

enter image description here

Upvotes: 1

Related Questions