1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus MCP SDK package.
7: *
8: * (c) 2026 John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Mcp\Core\Exception;
15:
16: /**
17: * Thrown when an HTTP exchange answers with a status that carries no JSON-RPC payload settling
18: * the message the exchange was sent for.
19: */
20: final class UnexpectedHttpStatusException extends \RuntimeException implements McpExceptionInterface
21: {
22: private const int MAX_BODY_BYTES = 8_192;
23:
24: /**
25: * The leading bytes of the answer's body, or null where the body was not read.
26: */
27: public readonly ?string $body;
28:
29: public function __construct(
30: public readonly int $status,
31: ?string $body = null,
32: ) {
33: $this->body = null === $body ? null : substr($body, 0, self::MAX_BODY_BYTES);
34:
35: parent::__construct(\sprintf('The endpoint answered %d where 200 or 202 was expected.', $status));
36: }
37: }
38: