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

@@ -15,6 +15,7 @@ class Add extends Component
public string $value;
public bool $is_build_time = false;
protected $listeners = ['clearAddEnv' => 'clear'];
protected $rules = [
'key' => 'required|string',
'value' => 'required|string',
@@ -27,25 +28,16 @@ class Add extends Component
public function submit()
{
$this->validate();
try {
$application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;
EnvironmentVariable::create([
'key' => $this->key,
'value' => $this->value,
'is_build_time' => $this->is_build_time,
'application_id' => $application_id,
]);
$this->emit('refreshEnvs');
$this->key = '';
$this->value = '';
} catch (mixed $e) {
dd('asdf');
if ($e instanceof QueryException) {
dd($e->errorInfo);
$this->emit('error', $e->errorInfo[2]);
} else {
$this->emit('error', $e);
}
}
$this->emitUp('submit', [
'key' => $this->key,
'value' => $this->value,
'is_build_time' => $this->is_build_time,
]);
}
public function clear()
{
$this->key = '';
$this->value = '';
$this->is_build_time = false;
}
}

View File

@@ -3,14 +3,30 @@
namespace App\Http\Livewire\Project\Application\EnvironmentVariable;
use App\Models\Application;
use App\Models\EnvironmentVariable;
use Livewire\Component;
class All extends Component
{
public Application $application;
protected $listeners = ['refreshEnvs'];
protected $listeners = ['refreshEnvs', 'submit'];
public function refreshEnvs()
{
$this->application->refresh();
}
public function submit($data)
{
try {
EnvironmentVariable::create([
'key' => $data['key'],
'value' => $data['value'],
'is_build_time' => $data['is_build_time'],
'application_id' => $this->application->id,
]);
$this->application->refresh();
$this->emit('clearAddEnv');
} catch (\Exception $e) {
return generalErrorHandlerLivewire($e, $this);
}
}
}