Show a proper error message table when encountering an invalid regex statement on SQLite

This is related to #289
This commit is contained in:
Jan Böhmer 2023-05-09 00:26:40 +02:00
parent 2c33b381c1
commit b0ab43c39a
3 changed files with 99 additions and 13 deletions

View file

@ -31,6 +31,7 @@ use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Exceptions\InvalidRegexException;
use App\Form\Filters\PartFilterType;
use App\Services\Parts\PartsTableActionHandler;
use App\Services\Trees\NodesListBuilder;
@ -151,19 +152,19 @@ class PartListsController extends AbstractController
if ($table->isCallback()) {
try {
return $table->getResponse();
} catch (DriverException $driverException) {
if ($driverException->getCode() === 1139) {
//Show only the part after "1139"
$regex_message = preg_replace('/^.*1139 /', '', $driverException->getMessage());
$errors = $this->translator->trans('part.table.invalid_regex') . ': ' . $regex_message;
return ErrorDataTable::errorTable($this->dataTableFactory, $request, $errors);
} else {
throw $driverException;
try {
return $table->getResponse();
} catch (DriverException $driverException) {
if ($driverException->getCode() === 1139) {
//Convert the driver exception to InvalidRegexException so it has the same hanlder as for SQLite
throw InvalidRegexException::fromDriverException($driverException);
} else {
throw $driverException;
}
}
} catch (InvalidRegexException $exception) {
$errors = $this->translator->trans('part.table.invalid_regex').': '.$exception->getReason();
return ErrorDataTable::errorTable($this->dataTableFactory, $request, $errors);
}
}