Skip to content

Commit 9d1a101

Browse files
committed
fix: add missing QueryException import and improve error handling in ExceptionHandler
1 parent 473b991 commit 9d1a101

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/app/Exceptions/ExceptionHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Auth\AuthenticationException;
7+
use Illuminate\Database\QueryException;
78
use Illuminate\Foundation\Configuration\Exceptions;
89
use Illuminate\Http\Request;
910
use Illuminate\Http\Response;
@@ -23,7 +24,8 @@ public static function handle(Exceptions $exceptions): void
2324
public static function render(Throwable $exception, Request $request): Response|false
2425
{
2526
if ($exception->getCode() === '22P02') {
26-
$message = str_replace('ERROR: ', '', explode("\n", $exception->errorInfo[2])[0]);
27+
/** @var QueryException $exception */
28+
$message = str_replace('ERROR: ', '', explode("\n", $exception->errorInfo[2] ?? '')[0]);
2729
throw new NotFoundHttpException($message);
2830
}
2931

0 commit comments

Comments
 (0)