Review follow-ups:
- verifyMastodon was the last hardcoded host left after the PR moved
LinkedIn/YouTube/Bluesky to config. Adds trypost.platforms.mastodon
.default_instance (env MASTODON_DEFAULT_INSTANCE) and reads from it.
- refreshToken() docblock now declares @throws PlatformUnavailableException
(the whole point of the PR was missing from its contract).
- Strip the new explanatory comments inside catch blocks and tests —
rationale lives in the commit / PR, not inline. The two comments
inside empty `catch (TokenExpiredException) {}` blocks stay because
there the comment is the only thing telling the reader why the
exception is swallowed.
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Exceptions\PlatformUnavailableException;
|
|
use App\Exceptions\TokenExpiredException;
|
|
use App\Models\SocialAccount;
|
|
use App\Services\Social\ConnectionVerifier;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Throwable;
|
|
|
|
class RefreshSocialToken implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 1;
|
|
|
|
public function __construct(public SocialAccount $account) {}
|
|
|
|
public function handle(ConnectionVerifier $verifier): void
|
|
{
|
|
try {
|
|
$verifier->refreshToken($this->account);
|
|
} catch (PlatformUnavailableException $e) {
|
|
Log::warning('Token refresh skipped: platform unavailable', [
|
|
'account_id' => $this->account->id,
|
|
'platform' => $this->account->platform->value,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
} catch (TokenExpiredException $e) {
|
|
$this->account->markAsTokenExpired($e->getMessage());
|
|
} catch (Throwable $e) {
|
|
Log::warning('Proactive token refresh failed', [
|
|
'account_id' => $this->account->id,
|
|
'platform' => $this->account->platform->value,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
}
|