fix: prevent fatal errors when LinkedIn authorization fails - #1100
Open
lucadobrescu wants to merge 3 commits into
Open
fix: prevent fatal errors when LinkedIn authorization fails#1100lucadobrescu wants to merge 3 commits into
lucadobrescu wants to merge 3 commits into
Conversation
LinkedIn authorization failures could crash to the WordPress critical-error screen instead of surfacing the LinkedIn error: - authorize() called the non-existent Exception::getDescription() in its catch block, turning any caught error into a second fatal - add_account_with_app() ran array_pop() on the result of unserialize() without validating the payload, fataling on PHP 8 when the popup posts back an error payload instead of account data - add_account_li() ignored the add_account_with_app() return value and registered the service regardless - sign-in-btn.vue parsed every popup message as account data Validation failures now log the LinkedIn error to the Revive Social log and answer the REST call with a code 400 response. Adds e2e coverage for the malformed-payload paths (red on the old code) plus a happy-path guard, and drops the stale PHPStan baseline entry for the fixed getDescription() call. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Adds regression tests for the remaining validation branches: empty payload, pages without a notify entry, notify-only pages with no accounts (asserting no service gets registered), the LinkedIn error landing in the plugin log, and the happy path now verifies the account is actually registered and exposed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The add_account_with_app() validation guarantees the accounts loop always runs, so PHPStan no longer reports 'Variable $account might not be defined' and the baseline ignore became unmatched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
When LinkedIn authorization fails during account connection, the plugin crashed to the WordPress critical-error screen instead of showing the LinkedIn error (issue #1098). The error-handling paths themselves fataled; this PR makes them report the failure and keep the dashboard alive.
What changed
Rop_Linkedin_Service::authorize()— the catch block calledException::getDescription(), which does not exist on plain exceptions, so any caught error (e.g. a failed token exchange) became a second fatal. It now falls back togetMessage()and no longer assumesHTTP_REFERERis set. The stale PHPStan baseline entry for this exact error is removed.Rop_Linkedin_Service::add_account_with_app()— an error payload without validpagesdata reachedarray_pop( false ), a fatalTypeErroron PHP 8. The payload is now validated (pagespresent, unserializes to a non-empty array, notify entry well-formed) and rejected with a logged error.Rop_Rest_Api::add_account_li()— previously ignored theadd_account_with_app()return value and registered the service even after a failed add. It now answers with a code400response pointing to the Revive Social log.sign-in-btn.vue— the popup message handler parsed every message as account data. Malformed JSON and error payloads are now dropped with a logged error instead of being sent to the server and reloading the page.E2E tests — new
linkedin-error-handling.spec.jscovers seven scenarios: missing, garbled, and empty payloads, pages without a notify entry, notify-only pages (asserting no service gets registered), the LinkedIn error landing in the plugin log, and a happy-path add that verifies the account is registered. The two malformed-payload tests fail with a fatal on the previous code.LinkedIn account connection flow
flowchart LR A[LinkedIn popup<br/>posts message] --> B{Changed:<br/>valid account<br/>payload?}:::changed B -- No --> C[Log error,<br/>stop loading] B -- Yes --> D[REST<br/>add_account_li] D --> E{New:<br/>payload passes<br/>validation?}:::added E -- No --> F[Code 400 +<br/>Revive Social log] E -- Yes --> G[Account added] H[authorize<br/>token exchange fails] --> I[Changed:<br/>log real LinkedIn error]:::changed classDef added fill:#1a7f37,color:#fff,stroke:#116329,stroke-width:3px classDef changed fill:#9a6700,color:#fff,stroke:#5c3d00,stroke-width:3px,stroke-dasharray:6 3Note
With
ROP_DEBUGon (any non-production environment) a missing-key payload is answered by the pre-existingRop_Exception_Handlerdebug output instead of the JSON400response. The e2e test accepts both shapes; production behavior is the400response.QA
Log in as an administrator and open the plugin dashboard at
/wp-admin/admin.php?page=TweetOldPost(Revive Social entry in the admin menu). In the browser DevTools console, simulate the error payload LinkedIn hands back on a failed authorization:Expect: a JSON response with
"code":"400"(no critical-error page, no HTTP 500 fatal).Reload the dashboard page.
Expect: the Accounts screen renders normally and LinkedIn still offers its sign-in button; no LinkedIn account was half-registered.
With a real LinkedIn app configured, start Sign in to LinkedIn from the Accounts tab and cancel/deny the authorization on the LinkedIn side.
Expect: the dashboard stays functional and the LinkedIn error is recorded in the plugin log (Revive Social dashboard → Logs) instead of a WordPress critical-error screen.
🤖 Generated with Claude Code