diff --git a/app/Exceptions/Social/FacebookPublishException.php b/app/Exceptions/Social/FacebookPublishException.php index 369609e0..e362bfd6 100644 --- a/app/Exceptions/Social/FacebookPublishException.php +++ b/app/Exceptions/Social/FacebookPublishException.php @@ -22,7 +22,7 @@ public static function fromApiResponse(mixed $response): static $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.php index c0bbf662..4b836d46 100644 --- a/app/Exceptions/Social/InstagramPublishException.php +++ b/app/Exceptions/Social/InstagramPublishException.php @@ -21,7 +21,7 @@ public static function fromApiResponse(mixed $response): static $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.php index 1a2026f2..7ab5f07a 100644 --- a/app/Exceptions/Social/ThreadsPublishException.php +++ b/app/Exceptions/Social/ThreadsPublishException.php @@ -20,7 +20,7 @@ public static function fromApiResponse(mixed $response): static $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.php index 8db2b141..f7394c8f 100644 --- a/tests/Unit/Exceptions/Social/FacebookPublishExceptionTest.php +++ b/tests/Unit/Exceptions/Social/FacebookPublishExceptionTest.php @@ -40,19 +40,22 @@ 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.php index 771bfae0..eb376431 100644 --- a/tests/Unit/Exceptions/Social/InstagramPublishExceptionTest.php +++ b/tests/Unit/Exceptions/Social/InstagramPublishExceptionTest.php @@ -84,13 +84,12 @@ ->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.php index 80d6ab3a..36995407 100644 --- a/tests/Unit/Exceptions/Social/ThreadsPublishExceptionTest.php +++ b/tests/Unit/Exceptions/Social/ThreadsPublishExceptionTest.php @@ -7,7 +7,7 @@ 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.',