IT-Service: Baumstruktur, HTML-Antworten, Fehlermeldungen, geschlossene Tickets, Meine IT im Profilkasten
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m57s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m9s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m13s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m57s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m9s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m13s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m30s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m7s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ab35a67406
commit
50ee85c06b
119 changed files with 611 additions and 463 deletions
|
|
@ -16,17 +16,44 @@ class OpenNitException extends RuntimeException
|
|||
|
||||
public static function fromStatus(int $status, array $body): self
|
||||
{
|
||||
$detail = is_string($body['message'] ?? null) ? $body['message'] : (is_string($body['error'] ?? null) ? $body['error'] : null);
|
||||
$detail = self::detail($body);
|
||||
|
||||
$message = match ($status) {
|
||||
400 => 'Die Angaben sind unvollständig oder ungültig.'.($detail ? " ({$detail})" : ''),
|
||||
401 => 'Die Verbindung zum IT-Service ist nicht richtig eingerichtet (Anmeldung abgelehnt). Bitte die Administration informieren.',
|
||||
403 => 'Der IT-Service erlaubt diesen Zugriff nicht.',
|
||||
404 => 'Nicht gefunden – vielleicht gehört der Eintrag zu einer anderen Person.',
|
||||
409 => $detail ?: 'Das Gerät ist in diesem Zeitraum nicht verfügbar.',
|
||||
$message = match (true) {
|
||||
$status === 401 => 'Die Verbindung zum IT-Service ist nicht richtig eingerichtet (Anmeldung abgelehnt). Bitte die Administration informieren.',
|
||||
$status === 403 => $detail ?: 'Der IT-Service erlaubt diesen Zugriff nicht.',
|
||||
$status === 404 => $detail ?: 'Nicht gefunden – vielleicht gehört der Eintrag zu einer anderen Person.',
|
||||
$status === 409 => $detail ?: 'Das Gerät ist in diesem Zeitraum nicht verfügbar.',
|
||||
// Übrige Eingabefehler (400, 422 …): die Meldung von OpenNIT zeigen, z. B. „Zeitraum zu lang“
|
||||
$status >= 400 && $status < 500 => $detail ?: 'Die Angaben sind unvollständig oder ungültig.',
|
||||
// Auch bei Serverfehlern eine kurze, lesbare Meldung von OpenNIT zeigen
|
||||
$detail !== null && mb_strlen($detail) <= 200 && ! str_contains($detail, 'Exception') => $detail,
|
||||
default => 'Der IT-Service ist gerade nicht erreichbar. Bitte später erneut versuchen.',
|
||||
};
|
||||
|
||||
return new self($message, $status, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fehlertext aus der Antwort: message, error oder die erste Feldmeldung.
|
||||
*
|
||||
* @param array<string, mixed> $body
|
||||
*/
|
||||
private static function detail(array $body): ?string
|
||||
{
|
||||
foreach (['message', 'error', 'detail'] as $key) {
|
||||
if (is_string($body[$key] ?? null) && trim($body[$key]) !== '') {
|
||||
return trim($body[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array) ($body['errors'] ?? []) as $messages) {
|
||||
$first = is_array($messages) ? reset($messages) : $messages;
|
||||
|
||||
if (is_string($first) && $first !== '') {
|
||||
return $first;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue