Lets the call sites drop the explicit null check ternary. The redactor itself owns the null handling — one less conditional at every caller.
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Exceptions\Social;
|
|
|
|
use App\Services\Social\TokenRedactor;
|
|
use RuntimeException;
|
|
|
|
abstract class SocialPublishException extends RuntimeException
|
|
{
|
|
public function __construct(
|
|
public readonly string $userMessage,
|
|
public readonly ErrorCategory $category,
|
|
public readonly ?string $platformErrorCode = null,
|
|
public readonly ?string $rawResponse = null,
|
|
) {
|
|
parent::__construct($userMessage);
|
|
}
|
|
|
|
/**
|
|
* @return array{platform: string, category: string, platform_error_code: ?string, user_message: string, raw_response: ?string}
|
|
*/
|
|
public function context(): array
|
|
{
|
|
return [
|
|
'platform' => static::platform(),
|
|
'category' => $this->category->value,
|
|
'platform_error_code' => $this->platformErrorCode,
|
|
'user_message' => $this->userMessage,
|
|
'raw_response' => TokenRedactor::redact($this->rawResponse),
|
|
];
|
|
}
|
|
|
|
abstract public static function fromApiResponse(mixed $response): static;
|
|
|
|
abstract public function platform(): string;
|
|
}
|