| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | namespace Nexus\Mcp\Core\Exception; |
| 15: | |
| 16: | use Nexus\Mcp\Core\JsonRpc\SafeDisplay; |
| 17: | use Nexus\Mcp\Core\Schema\Enum\ProtocolErrorCode; |
| 18: | use Nexus\Mcp\Core\Schema\RequestId; |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | final class MethodMisroutedException extends AbstractJsonRpcProtocolException |
| 25: | { |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | public function __construct( |
| 32: | string $method, |
| 33: | string $expectedShape, |
| 34: | string $receivedShape, |
| 35: | ?RequestId $requestId = null, |
| 36: | ?\Throwable $previous = null, |
| 37: | ) { |
| 38: | parent::__construct( |
| 39: | $requestId, |
| 40: | \sprintf( |
| 41: | 'Method "%s" must be sent as a %s, not a %s.', |
| 42: | SafeDisplay::sanitise($method), |
| 43: | $expectedShape, |
| 44: | $receivedShape, |
| 45: | ), |
| 46: | $previous, |
| 47: | ); |
| 48: | } |
| 49: | |
| 50: | #[\Override] |
| 51: | public static function getErrorCode(): ProtocolErrorCode |
| 52: | { |
| 53: | return ProtocolErrorCode::InvalidRequest; |
| 54: | } |
| 55: | } |
| 56: | |