Skip to content

Comments

Remove early return in response-validation handler to match pattern of other handlers#553

Open
Copilot wants to merge 3 commits intofeature/fix-headers-sendfrom
copilot/sub-pr-552
Open

Remove early return in response-validation handler to match pattern of other handlers#553
Copilot wants to merge 3 commits intofeature/fix-headers-sendfrom
copilot/sub-pr-552

Conversation

Copy link

Copilot AI commented Feb 18, 2026

The response-validation handler had an early return when headersSent was true, returning undefined and preventing validation logic from running. This was inconsistent with unauthorized.js, request-validation.js, and not-found.js handlers, which check headersSent only before setting status/sending responses.

Changes

  • Removed early return at handler entry
  • Added headersSent checks before each response operation (json/send/end)
  • Return response data instead of undefined when headers already sent
  • Validation and error logging now run regardless of header state

Before

export default (logger, validateResponse) => (context, request, response) => {
  if (response.headersSent) {
    return undefined  // Blocks all processing
  }
  
  const valid = validateResponse ? context.api.validateResponse(...) : null
  if (valid?.errors) {
    // validation logic
    if (!response.headersSent) {
      return response.status(502).json(errorResponse)
    }
    return undefined
  }
  return response.json(context.response)
}

After

export default (logger, validateResponse) => (context, request, response) => {
  const valid = validateResponse ? context.api.validateResponse(...) : null
  if (valid?.errors) {
    // validation logic runs regardless of headersSent
    if (!response.headersSent) {
      return response.status(502).json(errorResponse)
    }
    return errorResponse  // Return data for consistency
  }
  
  if (!response.headersSent) {
    return response.json(context.response)
  }
  return context.response
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 18, 2026 15:53
Co-authored-by: w3nl <3618143+w3nl@users.noreply.github.com>
Co-authored-by: w3nl <3618143+w3nl@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 18, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scarf.sh
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./report.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix preventing setting headers multiple times Remove early return in response-validation handler to match pattern of other handlers Feb 18, 2026
Copilot AI requested a review from w3nl February 18, 2026 15:57
@w3nl w3nl marked this pull request as ready for review February 18, 2026 16:02
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.

2 participants