Skip to content

[Backend] errorHandler does not guard res.headersSent - throws after a partial/streamed response #819

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

error.middleware.ts:9-56 unconditionally calls res.status(...).json(...) in every branch with no if (res.headersSent) return next(err) check. If an error surfaces after headers were already written (e.g. the SSE subscribe path writes res.writeHead(200) then can throw), this throws a secondary error and can crash the request instead of delegating to Express's default finalizer.

Acceptance criteria

  • Return next(err) immediately when res.headersSent is true
  • Add a unit test passing a response with headersSent=true and asserting next(err) is called and res.status is not invoked

Files to touch

  • backend/src/middleware/error.middleware.ts

Out of scope

  • Reworking error response shapes

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend related tasksbugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions