-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make all exceptions extend
BlueskyException
- Loading branch information
Showing
9 changed files
with
36 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\Bluesky\Exceptions; | ||
|
||
abstract class BlueskyClientException extends BlueskyException | ||
{ | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters