Skip to content

Guard error handler after headers are sent#939

Open
charlesedeh021-cell wants to merge 1 commit into
LabsCrypt:mainfrom
charlesedeh021-cell:fix/error-handler-headers-sent-819
Open

Guard error handler after headers are sent#939
charlesedeh021-cell wants to merge 1 commit into
LabsCrypt:mainfrom
charlesedeh021-cell:fix/error-handler-headers-sent-819

Conversation

@charlesedeh021-cell

@charlesedeh021-cell charlesedeh021-cell commented Jun 29, 2026

Copy link
Copy Markdown

Summary

  • Adds a
    es.headersSent guard to the global backend error handler.
  • Delegates to
    ext(err) when a streamed or partial response has already written headers.
  • Prevents the error middleware from attempting a second
    es.status(...).json(...) write after headers are sent.
  • Extends the existing error middleware test coverage for the streamed-response case.
  • Asserts that
    ext(err) is called and neither
    es.status nor
    es.json is invoked when headersSent is true.

Closes #819
Closes #817
Closes #818
Closes #820

Notes

This keeps the existing error response shapes unchanged. The only behavioral change is for post-header failures, where Express should continue through the normal error finalization path instead of the app trying to write another JSON response.

Testing

  • Not run: backend dependencies are not installed in this worktree.
  • Ran: git diff --check.

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