Repository navigation
fix(facebook): map five recurring Graph API rejections instead of "Unknown Error" - #2045
Closed
giladresisi wants to merge 2 commits into
Closed
giladresisi wants to merge 2 commits into
giladresisi wants to merge 2 commits into
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".
Strix Security ReviewNo security issues found. 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. |
Comment on lines
+231
to
+239
| if ( | ||
| body.indexOf('"error_subcode":33') > -1 && | ||
| body.indexOf('does not exist') > -1 | ||
| ) { | ||
| return { | ||
| type: 'bad-body' as const, | ||
| value: | ||
| 'The Facebook Page or post this was targeting no longer exists, please reconnect the channel and schedule again', | ||
| }; |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment.
Valid, fixed in the follow-up commit: the three subcode checks (33, 459, 492) now test /"error_subcode":NNN\b/ so a trailing digit no longer matches. Re-verified against all 1,827 production bodies (same 655 mapped, everything else still undefined) plus negative cases for 330, 4590 and 4920.
"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.
5 of 14 tasks
Collaborator
Author
|
Replaced by #2127, the same change rebased onto main. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 covered by their own PRs.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