fix: Facebook/Instagram/Threads OAuthException type incorrectly treated as token error — now only code 190 triggers TokenExpiredException
This commit is contained in:
parent
fbe49e917f
commit
da2b7ca9ca
6 changed files with 14 additions and 12 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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([
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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.',
|
||||
|
|
|
|||
Loading…
Reference in a new issue