Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
refactor: InstagramPublisher uses InstagramPublishException
Paulo Castellano21cd95d51287
diff --git a/app/Services/Social/InstagramPublisher.php b/app/Services/Social/InstagramPublisher.phpindex 9dfc687fd..eeac921b3 100644--- a/app/Services/Social/InstagramPublisher.php+++ b/app/Services/Social/InstagramPublisher.php@@ -5,6 +5,7 @@ declare(strict_types=1);namespace App\Services\Social;use App\Enums\PostPlatform\ContentType;+use App\Exceptions\Social\InstagramPublishException;use App\Exceptions\TokenExpiredException;use App\Models\PostPlatform;use App\Models\SocialAccount;@@ -14,24 +15,6 @@ use Illuminate\Support\Facades\Log;class InstagramPublisher{- /**- * Meta Graph API error codes that indicate token issues.- *- * @see https://developers.facebook.com/docs/graph-api/guides/error-handling- */- private const TOKEN_ERROR_CODES = [- 190, // Invalid OAuth access token- ];-- private const TOKEN_ERROR_SUBCODES = [- 458, // App not installed- 459, // User checkpointed- 460, // Password changed- 463, // Session expired- 464, // Unconfirmed user- 467, // Invalid access token- ];-private string $baseUrl = 'https://graph.instagram.com/v24.0';public function publish(PostPlatform $postPlatform): array@@ -99,7 +82,7 @@ class InstagramPublisher'status' => $containerResponse->status(),'body' => $containerResponse->body(),]);- $this->handleApiError($containerResponse, 'Instagram API error');+ $this->handleApiError($containerResponse);}$containerId = $containerResponse->json()['id'] ?? null;@@ -132,7 +115,7 @@ class InstagramPublisher'status' => $containerResponse->status(),'body' => $containerResponse->body(),]);- $this->handleApiError($containerResponse, 'Instagram API error');+ $this->handleApiError($containerResponse);}$containerId = $containerResponse->json()['id'] ?? null;@@ -173,7 +156,7 @@ class InstagramPublisher'status' => $containerResponse->status(),'body' => $containerResponse->body(),]);- $this->handleApiError($containerResponse, 'Instagram API error');+ $this->handleApiError($containerResponse);}$containerId = $containerResponse->json()['id'] ?? null;@@ -278,7 +261,7 @@ class InstagramPublisher'status' => $publishResponse->status(),'body' => $publishResponse->body(),]);- $this->handleApiError($publishResponse, 'Instagram publish error');+ $this->handleApiError($publishResponse);}$mediaId = $publishResponse->json()['id'];@@ -356,26 +339,8 @@ class InstagramPublisherLog::info('Instagram token refreshed successfully');}- private function handleApiError(Response $response, string $context): void+ private function handleApiError(Response $response): never{- $body = $response->json() ?? [];- $error = $body['error'] ?? [];- $errorCode = $error['code'] ?? null;- $errorSubcode = $error['error_subcode'] ?? null;- $errorType = $error['type'] ?? null;- $message = $error['message'] ?? $response->body();-- $isTokenError = $errorType === 'OAuthException'- || in_array($errorCode, self::TOKEN_ERROR_CODES)- || in_array($errorSubcode, self::TOKEN_ERROR_SUBCODES);-- if ($isTokenError) {- throw new TokenExpiredException(- "{$context}: {$message}",- $errorCode ? (string) $errorCode : null- );- }-- throw new \Exception("{$context}: {$message}");+ throw InstagramPublishException::fromApiResponse($response);}}