-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If LegacyIdException is thrown provide proper solution (#2291)
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\Exceptions\Handlers; | ||
|
||
use App\Contracts\Exceptions\Handlers\HttpExceptionHandler; | ||
use App\Exceptions\ModelDBException; | ||
use Illuminate\Database\QueryException; | ||
use Symfony\Component\HttpFoundation\Response as SymfonyResponse; | ||
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface as HttpException; | ||
|
||
/** | ||
* Class LegacyIdExceptionHandler. | ||
* | ||
* If SQLSTATE: Numeric value out of range: 1264 is throw it means we are interacting with 32 bit DB. | ||
* Advise to set config parameter. | ||
*/ | ||
class LegacyIdExceptionHandler implements HttpExceptionHandler | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function check(HttpException $e): bool | ||
{ | ||
do { | ||
if ( | ||
($e instanceof QueryException || $e instanceof ModelDBException) && | ||
str_contains($e->getMessage(), 'Numeric value out of range: 1264') | ||
) { | ||
return true; | ||
} | ||
} while ($e = $e->getPrevious()); | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function renderHttpException(SymfonyResponse $defaultResponse, HttpException $e): SymfonyResponse | ||
{ | ||
return response()->view('error.error', [ | ||
'code' => $e->getStatusCode(), | ||
'type' => class_basename($e), | ||
'message' => 'SQLSTATE: Numeric value out of range: 1264 for column \'legacy_id\'. To fix, please set `force_32bit_ids` to `1` in your Settings => More.', | ||
], $e->getStatusCode(), $e->getHeaders()); | ||
} | ||
} |