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
fix: Facebook/Instagram/Threads OAuthException type incorrectly treated as token error — now only code 190 triggers TokenExpiredException
Paulo Castellanoda2b7ca9caa5
diff --git a/app/Exceptions/Social/FacebookPublishException.php b/app/Exceptions/Social/FacebookPublishException.phpindex 369609e06..e362bfd69 100644--- a/app/Exceptions/Social/FacebookPublishException.php+++ b/app/Exceptions/Social/FacebookPublishException.php@@ -22,7 +22,7 @@ class FacebookPublishException extends SocialPublishException$tokenSubcodes = [458, 459, 460, 463, 464, 467];- if ($errorType === 'OAuthException' || $errorCode === 190 || in_array($errorSubcode, $tokenSubcodes, true)) {+ if ($errorCode === 190 || in_array($errorSubcode, $tokenSubcodes, true)) {throw new TokenExpiredException(message: $errorMessage,platformErrorCode: $errorCode !== null ? (string) $errorCode : null,diff --git a/app/Exceptions/Social/InstagramPublishException.php b/app/Exceptions/Social/InstagramPublishException.phpindex c0bbf6625..4b836d46d 100644--- a/app/Exceptions/Social/InstagramPublishException.php+++ b/app/Exceptions/Social/InstagramPublishException.php@@ -21,7 +21,7 @@ class InstagramPublishException extends SocialPublishException$errorUserMsg = data_get($body, 'error.error_user_msg');$errorMessage = data_get($body, 'error.message', 'An unknown Instagram error occurred.');- if ($errorType === 'OAuthException' || $errorCode === 190) {+ if ($errorCode === 190) {throw new TokenExpiredException(message: $errorMessage,platformErrorCode: $errorCode !== null ? (string) $errorCode : null,diff --git a/app/Exceptions/Social/ThreadsPublishException.php b/app/Exceptions/Social/ThreadsPublishException.phpindex 1a2026f24..7ab5f07a5 100644--- a/app/Exceptions/Social/ThreadsPublishException.php+++ b/app/Exceptions/Social/ThreadsPublishException.php@@ -20,7 +20,7 @@ class ThreadsPublishException extends SocialPublishException$errorCode = data_get($body, 'error.code');$errorMessage = data_get($body, 'error.message', 'An unknown Threads error occurred.');- if ($errorType === 'OAuthException' || $errorCode === 190) {+ if ($errorCode === 190) {throw new TokenExpiredException(message: $errorMessage,platformErrorCode: $errorCode !== null ? (string) $errorCode : null,diff --git a/tests/Unit/Exceptions/Social/FacebookPublishExceptionTest.php b/tests/Unit/Exceptions/Social/FacebookPublishExceptionTest.phpindex 8db2b141c..f7394c8fd 100644--- a/tests/Unit/Exceptions/Social/FacebookPublishExceptionTest.php+++ b/tests/Unit/Exceptions/Social/FacebookPublishExceptionTest.php@@ -40,19 +40,22 @@ test('code 190 throws TokenExpiredException', function () {FacebookPublishException::fromApiResponse($fakeResponse);})->throws(TokenExpiredException::class);-test('OAuthException type throws TokenExpiredException', function () {+test('OAuthException with non-190 code does not throw TokenExpiredException', function () {$response = Http::response(['error' => [- 'message' => 'Invalid OAuth access token.',+ 'message' => 'There was a problem uploading your video file.','type' => 'OAuthException',- 'code' => 400,+ 'code' => 6000,],], 400);$fakeResponse = Http::fake(['*' => $response])->post('https://graph.facebook.com/test');- FacebookPublishException::fromApiResponse($fakeResponse);-})->throws(TokenExpiredException::class);+ $exception = FacebookPublishException::fromApiResponse($fakeResponse);++ expect($exception)->toBeInstanceOf(FacebookPublishException::class);+ expect($exception->category)->toBe(ErrorCategory::MediaFormat);+});test('code 4 maps to RateLimit category', function () {$response = Http::response([diff --git a/tests/Unit/Exceptions/Social/InstagramPublishExceptionTest.php b/tests/Unit/Exceptions/Social/InstagramPublishExceptionTest.phpindex 771bfae0f..eb376431a 100644--- a/tests/Unit/Exceptions/Social/InstagramPublishExceptionTest.php+++ b/tests/Unit/Exceptions/Social/InstagramPublishExceptionTest.php@@ -84,13 +84,12 @@ test('known subcode 2207010 maps to ContentPolicy category', function () {->and($exception->userMessage)->toBe('Caption is too long (max 2,200 characters, 30 hashtags, 20 @mentions).');});-test('OAuthException type throws TokenExpiredException', function () {+test('code 190 throws TokenExpiredException', function () {$response = Http::response(['error' => ['message' => 'Invalid OAuth access token','type' => 'OAuthException',- 'code' => 400,- 'error_subcode' => 463,+ 'code' => 190,],], 400);diff --git a/tests/Unit/Exceptions/Social/ThreadsPublishExceptionTest.php b/tests/Unit/Exceptions/Social/ThreadsPublishExceptionTest.phpindex 80d6ab3a2..369954075 100644--- a/tests/Unit/Exceptions/Social/ThreadsPublishExceptionTest.php+++ b/tests/Unit/Exceptions/Social/ThreadsPublishExceptionTest.php@@ -7,7 +7,7 @@ use App\Exceptions\Social\ThreadsPublishException;use App\Exceptions\TokenExpiredException;use Illuminate\Support\Facades\Http;-test('OAuthException type throws TokenExpiredException', function () {+test('code 190 throws TokenExpiredException', function () {$response = Http::response(['error' => ['message' => 'Invalid OAuth access token.',