Repository navigation
fix(facebook): map five recurring Graph API rejections instead of "Unknown Error" - #2127
Conversation
…known Error" Adds handleErrors branches for 190/459 (checkpoint), 190/492 (no Page role), the 190 missing pages_* permissions body, 100/33 object does not exist, and Facebook's HTML outage page, so users see the reason and the right outcome (fail, reconnect, or retry) instead of "Unknown Error".
"error_subcode":33 as a substring also matched 330 and 331; the same held for 459 and 492. Test the three subcodes with a trailing word boundary instead.
Strix Security ReviewNo security issues found. Review summaryReviewed the single changed file, Updated for Reviewed by Strix |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Replaces #2045 (same change, rebased onto main).
What kind of change does this PR introduce?
Bug fix (backend, Facebook provider error mapping). Adds five branches to
handleErrorsinfacebook.provider.tsso responses that today surface as "Unknown Error" get a readable message and the right outcome:190/ subcode459(user checkpointed):bad-body, tells the user to log in at facebook.com and resolve the security check.190/ subcode492(no role on the Page):bad-body, tells the user to get a Page role from an admin, then reconnect.190"Any of the pages_read_engagement, ... permission(s) must be granted before impersonating a user's page":refresh-token, so the channel is flagged for reconnection with all permissions.100/ subcode33"Object with ID ... does not exist":bad-body, the target Page or post is gone, no point retrying.retry.The
retrytype is added to the method's return union. The new branches sit before the existing loose'490'substring match so it cannot swallow them. No existing mapping changed, and the generic fetch/retry logic insocial.abstract.tsis untouched.Why was this change needed?
The production Errors table has 1,827 Facebook rows in the last 45 days whose only message is "Unknown Error". Decoding the raw Graph API bodies stored in the failure details shows they are a handful of well-defined responses. The five mapped here account for 655 of them:
100/33"does not exist". Almost all target an integration that was soft-deleted and re-added, so the stored page id no longer exists on Facebook. These were being retried for nothing. Blocking post creation on deleted channels landed in fix(posts): reject post creation on soft-deleted channels #1921; the workflow-side guard onintegration.deletedAtis deliberately left for the next workflow version bump.pages_*permissions body. Meta's error reference lists code 200-299 / missing permissions as "handle the missing permissions", which for us means re-granting them in the login dialog, hencerefresh-token.190/492and 45 are190/459. Per Meta's error reference these need the user to fix a Page role or a checkpoint on Facebook itself, so a reconnect prompt would be misleading; they now fail with the Facebook-side instruction.The rest of the "Unknown Error" volume is the "Page not accessible" token error (#1881) and the
(#200)permission family (#1892), both already merged into main. The(#200)branch sits ahead of the new permissions branch inhandleErrors, so(#200)bodies that merely list permission names keep their curated message.Meta error reference: https://developers.facebook.com/docs/graph-api/guides/error-handling
Other information:
Verified by running the updated
handleErrorsagainst every distinct Facebook "Unknown Error" body from production in the last 45 days: the five responses above map to the intended type and message, every other body still returnsundefined, and all pre-existing mappings produce the same results as before.tsconnestjs-librariesreports no new errors.QA
libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts, callnew FacebookProvider().handleErrors(body, 400)(for example from a scratch ts-node script at the repo root) with{"error":{"message":"x","code":190,"error_subcode":459}}; expecttype: 'bad-body'and a message about resolving a security check at facebook.com.{"error":{"message":"x","code":190,"error_subcode":492}}; expecttype: 'bad-body'and a message about needing a role on the Page.{"error":{"message":"Any of the pages_read_engagement, pages_manage_metadata permission(s) must be granted before impersonating a user's page.","code":190}}; expecttype: 'refresh-token'.{"error":{"message":"Unsupported post request. Object with ID '123' does not exist, cannot be loaded due to missing permissions, or does not support this operation.","code":100,"error_subcode":33}}; expecttype: 'bad-body'and a message saying the target no longer exists.<html><title>Facebook | Error</title><body>Sorry, something went wrong. We're working on it and we'll get it fixed as soon as we can.</body></html>; expecttype: 'retry'.{"error":{"message":"(#200) If posting to a group, requires app being installed in the group, and either publish_to_groups permission with user token, or pages_read_engagement","code":200}}; expectundefined(the permissions branch must not catch(#200)bodies that merely list permission names).{"error":{"message":"Error validating access token","code":190}}; expect the pre-existingrefresh-tokenresult, unchanged.Checklist:
Put a "X" in the boxes below to indicate you have followed the checklist;
🤖 Generated with Claude Code
https://claude.ai/code/session_01GBHogYQMvY5zHT7qkdUQAT