From 32fa5d61139190a5bfa11999affc4f091c2310fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Ignacio=20Torres?= Date: Sun, 17 May 2026 00:59:53 -0700 Subject: [PATCH] fix: parameter error messages --- .../Pds/Atproto/Identity/ResolveHandleAction.php | 13 ++++++------- src/Application/Actions/Pds/XrpcException.php | 15 +++++++++++++++ .../Actions/Pds/XrpcExceptionTest.php | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Application/Actions/Pds/Atproto/Identity/ResolveHandleAction.php b/src/Application/Actions/Pds/Atproto/Identity/ResolveHandleAction.php index 9de1f3b..bd21085 100644 --- a/src/Application/Actions/Pds/Atproto/Identity/ResolveHandleAction.php +++ b/src/Application/Actions/Pds/Atproto/Identity/ResolveHandleAction.php @@ -73,15 +73,14 @@ class ResolveHandleAction extends PdsAction private function validateHandle(string $handle): void { - $errorCode = 'InvalidHandle'; $length = strlen($handle); - if ($length < 3) { - throw XrpcException::invalidRequest('Handle too short', $errorCode); - } - - if ($length > 18) { - throw XrpcException::invalidRequest('Handle too long', $errorCode); + if ($length < 3 || $length > 18) { + throw XrpcException::invalidParam( + $this->actionName, + 'Invalid handle', + $handle + ); } } } diff --git a/src/Application/Actions/Pds/XrpcException.php b/src/Application/Actions/Pds/XrpcException.php index eb7ae18..616a979 100644 --- a/src/Application/Actions/Pds/XrpcException.php +++ b/src/Application/Actions/Pds/XrpcException.php @@ -54,6 +54,21 @@ class XrpcException extends RuntimeException ); } + public static function invalidParam( + string $actionName, + string $reason, + string $value + ): self { + return self::invalidRequest( + sprintf( + 'Invalid %s params: %s (got "%s")', + $actionName, + $reason, + $value + ) + ); + } + public static function invalidRequest(string $message, string $error = 'InvalidRequest'): self { return new self($error, $message, StatusCodeInterface::STATUS_BAD_REQUEST); diff --git a/tests/Application/Actions/Pds/XrpcExceptionTest.php b/tests/Application/Actions/Pds/XrpcExceptionTest.php index eba9787..bc8838f 100644 --- a/tests/Application/Actions/Pds/XrpcExceptionTest.php +++ b/tests/Application/Actions/Pds/XrpcExceptionTest.php @@ -55,4 +55,20 @@ class XrpcExceptionTest extends TestCase ); $this->assertSame(400, $exception->getStatusCode()); } + + public function testInvalidParamFormatsMessageWithValue(): void + { + $exception = XrpcException::invalidParam( + 'com.atproto.identity.resolveHandle', + 'Invalid handle', + 'a' + ); + + $this->assertSame('InvalidRequest', $exception->getError()); + $this->assertSame( + 'Invalid com.atproto.identity.resolveHandle params: Invalid handle (got "a")', + $exception->getMessage() + ); + $this->assertSame(400, $exception->getStatusCode()); + } } -- 2.51.2