diff --git a/app/Console/Commands/SyncChurchToolsCommand.php b/app/Console/Commands/SyncChurchToolsCommand.php index c1dde2e..5fdd4e8 100644 --- a/app/Console/Commands/SyncChurchToolsCommand.php +++ b/app/Console/Commands/SyncChurchToolsCommand.php @@ -3,6 +3,9 @@ namespace App\Console\Commands; use App\Services\ChurchToolsService; +use CTApi\Exceptions\CTConnectException; +use CTApi\Exceptions\CTPermissionException; +use CTApi\Exceptions\CTRequestException; use Illuminate\Console\Command; use Throwable; @@ -24,8 +27,44 @@ public function handle(ChurchToolsService $churchToolsService): int $this->line('Nicht gematchte Songs: '.$summary['unmatched_songs_count']); return self::SUCCESS; - } catch (Throwable $exception) { - $this->error('Fehler beim Synchronisieren: '.$exception->getMessage()); + } catch (CTPermissionException $e) { + $this->error('Authentifizierungsfehler: API-Token ungueltig oder abgelaufen.'); + $this->error('Bitte pruefe CTS_API_TOKEN in der .env Datei.'); + $this->line(' Details: '.$e->getMessage()); + + if ($this->getOutput()->isVerbose()) { + $this->line(' Exception: '.$e::class); + $this->line(' Trace: '.$e->getTraceAsString()); + } + + return self::FAILURE; + } catch (CTConnectException $e) { + $this->error('Verbindungsfehler: ChurchTools Server nicht erreichbar.'); + $this->error('Bitte pruefe CTS_API_URL in der .env Datei und die Netzwerkverbindung.'); + $this->line(' Details: '.$e->getMessage()); + + if ($this->getOutput()->isVerbose()) { + $this->line(' Exception: '.$e::class); + $this->line(' Trace: '.$e->getTraceAsString()); + } + + return self::FAILURE; + } catch (CTRequestException $e) { + $this->error('API-Fehler: '.$e->getMessage()); + $this->line(' Exception: '.$e::class); + + if ($this->getOutput()->isVerbose()) { + $this->line(' Trace: '.$e->getTraceAsString()); + } + + return self::FAILURE; + } catch (Throwable $e) { + $this->error('Fehler beim Synchronisieren: '.$e->getMessage()); + $this->line(' Exception: '.$e::class); + + if ($this->getOutput()->isVerbose()) { + $this->line(' Trace: '.$e->getTraceAsString()); + } return self::FAILURE; } diff --git a/app/Http/Controllers/SyncController.php b/app/Http/Controllers/SyncController.php index 317ca8a..2caa652 100644 --- a/app/Http/Controllers/SyncController.php +++ b/app/Http/Controllers/SyncController.php @@ -3,7 +3,10 @@ namespace App\Http\Controllers; use App\Services\ChurchToolsService; +use CTApi\Exceptions\CTConnectException; +use CTApi\Exceptions\CTPermissionException; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Log; class SyncController extends Controller { @@ -13,7 +16,26 @@ public function sync(ChurchToolsService $service): RedirectResponse $service->sync(); return back()->with('success', 'Daten wurden aktualisiert'); + } catch (CTPermissionException $e) { + Log::error('CTS Sync: Authentifizierungsfehler', [ + 'nachricht' => $e->getMessage(), + 'exception_klasse' => $e::class, + ]); + + return back()->with('error', 'Sync fehlgeschlagen: Authentifizierung abgelehnt. Bitte prüfe den API-Token in der .env Datei.'); + } catch (CTConnectException $e) { + Log::error('CTS Sync: Verbindungsfehler', [ + 'nachricht' => $e->getMessage(), + 'exception_klasse' => $e::class, + ]); + + return back()->with('error', 'Sync fehlgeschlagen: Verbindung zu ChurchTools nicht möglich. Bitte prüfe die URL und Netzwerkverbindung.'); } catch (\Throwable $e) { + Log::error('CTS Sync: Unerwarteter Fehler', [ + 'nachricht' => $e->getMessage(), + 'exception_klasse' => $e::class, + ]); + return back()->with('error', 'Sync fehlgeschlagen: '.$e->getMessage()); } }