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

@@ -14,6 +14,8 @@ class Add extends Component
public string $name;
public string $mount_path;
public string|null $host_path = null;
protected $listeners = ['clearAddStorage' => 'clear'];
protected $rules = [
'name' => 'required|string',
'mount_path' => 'required|string',
@@ -26,27 +28,16 @@ class Add extends Component
public function submit()
{
$this->validate();
try {
$application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;
LocalPersistentVolume::create([
'name' => $this->name,
'mount_path' => $this->mount_path,
'host_path' => $this->host_path,
'resource_id' => $application_id,
'resource_type' => Application::class,
]);
$this->emit('refreshStorages');
$this->name = '';
$this->mount_path = '';
$this->host_path = '';
} 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', [
'name' => $this->name,
'mount_path' => $this->mount_path,
'host_path' => $this->host_path,
]);
}
public function clear()
{
$this->name = '';
$this->mount_path = '';
$this->host_path = null;
}
}