CodeFehlerAntwort.php
Pfad: src/Infrastructure/Http/CodeFehlerAntwort.php
Ext: php
Größe: 1628 Bytes
Geändert: 2026-07-16 10:17:53+02
<?php
declare(strict_types=1);
namespace Demo\Infrastructure\Http;
use PDOException;
use Throwable;
/**
* Liefert nutzerfreundliche Fehlerantworten für /code-Routen.
*/
final class CodeFehlerAntwort
{
/**
* Prüft auf fehlende Code-Relation in der DB und liefert ggf. 500-Seite.
*
* @param Throwable $throwable Aufgetretener Fehler.
* @return Response|null Fehlermeldung oder null für andere Fehler.
*/
public function fehlendeCodeTabelle(Throwable $throwable): ?Response
{
if (!$throwable instanceof PDOException) {
return null;
}
if ($throwable->getCode() !== '42P01'
&& str_contains(
strtolower((string) $throwable->getMessage()),
'relation "code_datei"'
)
=== false
) {
return null;
}
$meldung = strtolower((string) $throwable->getMessage());
if (!str_contains($meldung, 'code_datei')) {
return null;
}
$text = '<!doctype html><html><head><meta charset="UTF-8">'
. '<title>Code-Migration fehlt</title></head><body>'
. '<h1>Codeansicht aktuell nicht verfügbar</h1>'
. '<p>Die Tabelle <code>code_datei</code> ist in der '
. 'Datenbank nicht vorhanden.</p>'
. '<p>Bitte Migration <strong>0009_code_datei.sql</strong> '
. 'einspielen, dann ist die Ansicht wieder verfügbar.'
. '</p></body></html>';
return new Response(
500,
'text/html; charset=UTF-8',
$text
);
}
}