magic search bar

This commit is contained in:
Andras Bacsai
2023-05-11 15:20:02 +02:00
parent 8e1c6d2bd2
commit 70d032ff23
17 changed files with 686 additions and 481 deletions

View File

@@ -17,22 +17,31 @@ use Illuminate\Support\Str;
if (!function_exists('generalErrorHandler')) {
function generalErrorHandler(\Throwable $e, $that = null)
function generalErrorHandler(\Throwable $e, $that = null, $isJson = false)
{
if ($that) {
try {
if ($e instanceof QueryException) {
if ($e->errorInfo[0] === '23505') {
$that->emit('error', 'Duplicate entry found.');
throw new \Exception('Duplicate entry found.', '23505');
} else if (count($e->errorInfo) === 4) {
$that->emit('error', $e->errorInfo[3]);
throw new \Exception($e->errorInfo[3]);
} else {
$that->emit('error', $e->errorInfo[2]);
throw new \Exception($e->errorInfo[2]);
}
} else {
$that->emit('error', $e->getMessage());
throw new \Exception($e->getMessage());
}
} catch (\Throwable $error) {
if ($that) {
$that->emit('error', $error);
} elseif ($isJson) {
return response()->json([
'code' => $error->getCode(),
'error' => $error->getMessage(),
]);
} else {
dump('Duplicate entry found.');
}
} else {
dump($e);
}
}
}