fix error handling

This commit is contained in:
Andras Bacsai
2023-05-05 14:20:10 +02:00
parent 80e915c015
commit 631b61e11c
8 changed files with 84 additions and 53 deletions

View File

@@ -4,6 +4,7 @@ use App\Actions\CoolifyTask\PrepareCoolifyTask;
use App\Data\CoolifyTaskArgs;
use App\Models\Server;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\QueryException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@ -11,6 +12,20 @@ use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
use Spatie\Activitylog\Contracts\Activity;
if (!function_exists('generalErrorHandlerLivewire')) {
function generalErrorHandlerLivewire(\Throwable $e, $that)
{
if ($e instanceof QueryException) {
if ($e->errorInfo[0] === '23505') {
$that->emit('error', 'Duplicate entry found.');
} else {
$that->emit('error', $e->errorInfo[3]);
}
} else {
$that->emit('error', $e);
}
}
}
if (!function_exists('remoteProcess')) {
/**
* Run a Remote Process, which SSH's asynchronously into a machine to run the command(s).