diff --git a/src/Exceptions/BlueskyClientException.php b/src/Exceptions/BlueskyClientException.php new file mode 100644 index 0000000..d193064 --- /dev/null +++ b/src/Exceptions/BlueskyClientException.php @@ -0,0 +1,28 @@ + new static("Account is suspended ({$suffix})"), + 'ExpiredToken' => new static("Token is expired ({$suffix})"), + 'InvalidToken' => new static("Token is invalid ({$suffix})"), + default => new static(static::getDefaultMessage() . " ({$suffix})") + }; + } + + abstract protected static function getDefaultMessage(): string; + + protected static function createSuffix(int $status, ?string $error, ?string $message): string + { + return str($status) + ->when($error || $message) + ->append(', ' . implode(': ', array_filter([$error, $message]))) + ->toString(); + } +} diff --git a/src/Exceptions/BlueskyException.php b/src/Exceptions/BlueskyException.php index f8663f7..a51ad9f 100644 --- a/src/Exceptions/BlueskyException.php +++ b/src/Exceptions/BlueskyException.php @@ -4,25 +4,4 @@ abstract class BlueskyException extends \Exception { - public static function create(int $status, ?string $error, ?string $message): static - { - $suffix = static::createSuffix($status, $error, $message); - - return match ($error) { - 'AccountTakedown' => new static("Account is suspended ({$suffix})"), - 'ExpiredToken' => new static("Token is expired ({$suffix})"), - 'InvalidToken' => new static("Token is invalid ({$suffix})"), - default => new static(static::getDefaultMessage() . " ({$suffix})") - }; - } - - abstract protected static function getDefaultMessage(): string; - - protected static function createSuffix(int $status, ?string $error, ?string $message): string - { - return str($status) - ->when($error || $message) - ->append(', ' . implode(': ', array_filter([$error, $message]))) - ->toString(); - } } diff --git a/src/Exceptions/CouldNotCreatePost.php b/src/Exceptions/CouldNotCreatePost.php index e9392db..21ba5f6 100644 --- a/src/Exceptions/CouldNotCreatePost.php +++ b/src/Exceptions/CouldNotCreatePost.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Bluesky\Exceptions; -final class CouldNotCreatePost extends BlueskyException +final class CouldNotCreatePost extends BlueskyClientException { protected static function getDefaultMessage(): string { diff --git a/src/Exceptions/CouldNotCreateSession.php b/src/Exceptions/CouldNotCreateSession.php index dba699a..e9c4e99 100644 --- a/src/Exceptions/CouldNotCreateSession.php +++ b/src/Exceptions/CouldNotCreateSession.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Bluesky\Exceptions; -final class CouldNotCreateSession extends BlueskyException +final class CouldNotCreateSession extends BlueskyClientException { protected static function getDefaultMessage(): string { diff --git a/src/Exceptions/CouldNotRefreshSession.php b/src/Exceptions/CouldNotRefreshSession.php index 3d242cd..8e7e240 100644 --- a/src/Exceptions/CouldNotRefreshSession.php +++ b/src/Exceptions/CouldNotRefreshSession.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Bluesky\Exceptions; -final class CouldNotRefreshSession extends BlueskyException +final class CouldNotRefreshSession extends BlueskyClientException { protected static function getDefaultMessage(): string { diff --git a/src/Exceptions/CouldNotResolveHandle.php b/src/Exceptions/CouldNotResolveHandle.php index b3c6886..ba3fe68 100644 --- a/src/Exceptions/CouldNotResolveHandle.php +++ b/src/Exceptions/CouldNotResolveHandle.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Bluesky\Exceptions; -final class CouldNotResolveHandle extends BlueskyException +final class CouldNotResolveHandle extends BlueskyClientException { protected static function getDefaultMessage(): string { diff --git a/src/Exceptions/NoBlueskyChannel.php b/src/Exceptions/NoBlueskyChannel.php index 8d68de8..78f4e45 100644 --- a/src/Exceptions/NoBlueskyChannel.php +++ b/src/Exceptions/NoBlueskyChannel.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Bluesky\Exceptions; -final class NoBlueskyChannel extends \Exception +final class NoBlueskyChannel extends BlueskyException { public static function create(string $class): self { diff --git a/src/Exceptions/NoBlueskyIdentityFound.php b/src/Exceptions/NoBlueskyIdentityFound.php index 42da4d3..d5afe2e 100644 --- a/src/Exceptions/NoBlueskyIdentityFound.php +++ b/src/Exceptions/NoBlueskyIdentityFound.php @@ -2,7 +2,7 @@ namespace NotificationChannels\Bluesky\Exceptions; -final class NoBlueskyIdentityFound extends \Exception +final class NoBlueskyIdentityFound extends BlueskyException { public static function create(): self { diff --git a/src/RichText/Facets/Facet.php b/src/RichText/Facets/Facet.php index 1c28ab6..4060763 100644 --- a/src/RichText/Facets/Facet.php +++ b/src/RichText/Facets/Facet.php @@ -3,7 +3,7 @@ namespace NotificationChannels\Bluesky\RichText\Facets; use NotificationChannels\Bluesky\BlueskyClient; -use NotificationChannels\Bluesky\Exceptions\BlueskyException; +use NotificationChannels\Bluesky\Exceptions\BlueskyClientException; use NotificationChannels\Bluesky\RichText\Facets\Features\Link; use NotificationChannels\Bluesky\RichText\Facets\Features\Mention; @@ -52,7 +52,7 @@ private static function detectMentions(string $text, BlueskyClient $client): arr try { $did = $client->resolveHandle($handle); - } catch (BlueskyException) { + } catch (BlueskyClientException) { return null; }