Skip to content

Prevent session errors from swallowing API error responses#2059

Open
kayjoosten wants to merge 1 commit into
mainfrom
feature/issue-2051-push-endpoint-error-code
Open

Prevent session errors from swallowing API error responses#2059
kayjoosten wants to merge 1 commit into
mainfrom
feature/issue-2051-push-endpoint-error-code

Conversation

@kayjoosten

Copy link
Copy Markdown
Contributor

Summary

  • ApiHttpExceptionListener::onKernelException() calls ErrorReporter::reportError() before $event->setResponse(...). reportError() only wrapped its session-feedback write in a finally, not a catch — so on stateless routes (e.g. /api/connections metadata push), a session-start failure (e.g. "headers already sent") propagated out, skipped setResponse(), and the client got HTTP 200 instead of the intended 400/500.
  • Fix: catch Throwable around storeSessionFeedback() in ErrorReporter::reportError(), log it as a warning, and let the caller always finish. This applies to every exception listener that uses reportError() (API, feedback page, fallback), not just the push endpoint.

Test plan

  • phpunit --testsuite=unit --filter ErrorReporterTest (new regression test added)
  • phpunit --testsuite=eb4/unit/integration/functional — all pass
  • phpcs, phpmd, docheader — clean
  • Behat default suite — 300 scenarios / 5557 steps pass
  • lint:twig, phpcs-legacy, yarn lint — clean

Closes #2051

Why is this change needed?
Prior to this change, ErrorReporter::reportError() only wrapped its
call to storeSessionFeedback() in a finally block, not a catch. On
stateless routes (e.g. the /api/connections metadata push endpoint),
starting the native PHP session while storing feedback info can fail
(e.g. "headers already sent"). That failure propagated out of
reportError(), out of the calling exception listener, and skipped
$event->setResponse() in ApiHttpExceptionListener — so the intended
400/500 JSON error response for a failed push was never set and the
client received an HTTP 200 instead.

How does it address the issue?
This change adds a catch (Throwable) around storeSessionFeedback(),
logging the secondary failure as a warning instead of letting it
escape. reportError() can no longer throw, so every exception
listener that calls it (API, feedback page, fallback) reliably
finishes and sets its intended error response.

#2051
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push endpoint must return HTTP error code when push fails

1 participant