TokenRefreshClient classified every non-5xx/429 refresh failure as a dead token. Meta returns rate-limit (code 4/17) and transient (code 1/2) errors as HTTP 4xx with type OAuthException, so a throttled proactive refresh was disconnecting still-valid Instagram/Threads tokens — and the wider 24h/15-min refresh cadence raised the odds of hitting it. Classification now keys on error code 190 (the signal the publish exceptions already use): only a genuine 190 disconnects; every other Meta 4xx is treated as transient (PlatformUnavailable) and retried next cycle. The same over-broad type-based check in verifyInstagram/verifyFacebook/verifyThreads is replaced with the shared Meta\GraphError helper so verify and refresh agree.
30 lines
1 KiB
PHP
30 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Social\Meta;
|
|
|
|
/**
|
|
* Interprets Meta Graph API (Facebook / Instagram / Threads) error responses.
|
|
*
|
|
* Meta returns rate-limit and transient failures as an ordinary HTTP 4xx with
|
|
* type "OAuthException" (e.g. code 4 / 17 "too many calls", code 1 / 2
|
|
* "temporary problem"), so neither the HTTP status nor the error type can tell
|
|
* a dead token from a throttle. Only error code 190 means the access token
|
|
* itself is invalid or expired — the same signal the platform publish
|
|
* exceptions already use to decide a disconnect.
|
|
*/
|
|
class GraphError
|
|
{
|
|
/**
|
|
* Whether the given Meta Graph error body means the access token is
|
|
* genuinely invalid or expired (code 190), as opposed to a rate-limit or
|
|
* transient error that must not disconnect a still-valid token.
|
|
*
|
|
* @param array<string, mixed>|null $body
|
|
*/
|
|
public static function indicatesInvalidToken(?array $body): bool
|
|
{
|
|
return data_get($body, 'error.code') === 190;
|
|
}
|
|
}
|