Files
EKDOS/backend/src/N8n/Reply.php
T
Kyle Müller 7d82e807fc
EK-DOS-WEB bauen und ausrollen / frontend (push) Failing after 22s
EK-DOS-WEB bauen und ausrollen / backend (push) Failing after 27s
EK-DOS-WEB bauen und ausrollen / deploy (push) Skipped
Initial
2026-09-06 13:25:44 +02:00

46 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Ekdos\N8n;
use Ekdos\Support\Json;
/** Eine Antwort von n8n, roh und unbewertet. */
final readonly class Reply
{
public function __construct(
public int $status,
public string $body,
public string $contentType = '',
public bool $stale = false,
) {}
public function ok(): bool
{
return $this->status >= 200 && $this->status < 300;
}
/** Status fuer die Oberflaeche: ein Verbindungsfehler wird zu 502. */
public function statusOr(int $fallback = 502): int
{
return $this->status === 0 ? $fallback : $this->status;
}
public function decoded(): array
{
return Json::decode($this->body);
}
/** n8n liefert Listen mal als {"key":[...]}, mal als nacktes Array. */
public function items(string $key): array
{
return Json::listFrom($this->decoded(), $key);
}
public function asStale(): self
{
return new self($this->status, $this->body, $this->contentType, true);
}
}