Michael88's avatar

Catch sql connection exception

Hi , I'm trying to catch db connection error so the idea is when credentials for Postgres in env are wrong I need to show custom message, not the sql generated one SQLSTATE[08006] [7] connection... could someone help me with this please?

0 likes
1 reply
Nakov's avatar
Nakov
Best Answer
Level 73

You can catch the exception in your App\Exceptions\Handler.php class

change the register method with this:

public function register()
    {
        $this->reportable(function (QueryException $e) {
            dd('test');
        })->stop();
    }

refresh the page, and you'll see test.. Take a look here: https://laravel.com/docs/10.x/errors#introduction

1 like

Please or to participate in this conversation.