| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Schema; |
| 15: | |
| 16: | use Nexus\Assert\Assert; |
| 17: | use Nexus\Mcp\Core\Schema\Enum\ProtocolErrorCode; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | abstract readonly class Error implements Arrayable |
| 27: | { |
| 28: | public int $code; |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | public string $message; |
| 34: | |
| 35: | public function __construct( |
| 36: | int|ProtocolErrorCode $code, |
| 37: | string $message, |
| 38: | public mixed $data = null, |
| 39: | ) { |
| 40: | Assert::that($message)->isNonEmptyString('error "message" must be a non-empty string.'); |
| 41: | |
| 42: | $this->code = $code instanceof ProtocolErrorCode ? $code->value : $code; |
| 43: | $this->message = $message; |
| 44: | } |
| 45: | |
| 46: | #[\Override] |
| 47: | public function jsonSerialize(): array |
| 48: | { |
| 49: | return $this->toArray(); |
| 50: | } |
| 51: | } |
| 52: | |