Skip to content

Treat 429 and status 6 throttle responses as server errors that respe…#15

Merged
luke-owen-crowdhandler merged 1 commit into
masterfrom
maintenance/throttle-special-treatment
Jun 11, 2026
Merged

Treat 429 and status 6 throttle responses as server errors that respe…#15
luke-owen-crowdhandler merged 1 commit into
masterfrom
maintenance/throttle-special-treatment

Conversation

@luke-owen-crowdhandler

Copy link
Copy Markdown
Contributor

…ct failTrust

…ct failTrust

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts throttling behavior so that CrowdHandler API throttles (HTTP 429 and API result.status === 6) are handled like server-side failures, thereby respecting the failTrust setting in the CloudFront Viewer Request handler.

Changes:

  • Treat HTTP 429 responses from CrowdHandler API as “server error” responses in the HTTP helper (so failTrust logic is applied).
  • Add explicit handling for CrowdHandler throttle responses (status === 6) in viewerRequest, allowing fail-open when failTrust === true and otherwise redirecting to the safety net.

Reviewed changes

Copilot reviewed 2 out of 6 changed files in this pull request and generated 1 comment.

File Description
helpers/http.js Special-cases HTTP 429 to follow the same fallback path as server/network errors rather than client-error safety-net behavior.
handlerViewerRequest.js Adds status === 6 throttle handling to respect failTrust (fail-open) or redirect to safety net (fail-closed).
Comments suppressed due to low confidence (2)

helpers/http.js:62

  • After calling reject() for 429/4xx/5xx, the code continues to attach data/end handlers and will still call resolve(body) on end. Promises ignore subsequent resolve, but this does unnecessary work and makes the control flow harder to reason about. Return immediately after reject to stop processing the response body.
      // 429 throttle is treated as a server error so failTrust is respected
      if (res.statusCode === 429) {
        console.error(`[CH] API 429: throttled`);
        reject(JSON.stringify(dummyResponseData));
      } else if (res.statusCode >= 400 && res.statusCode < 500) {
        console.error(`[CH] API 4xx: ${res.statusCode}`);
        reject(JSON.stringify(clientErrorResponseData));
      } else if (res.statusCode < 200 || res.statusCode >= 300) {
        console.error(`[CH] API 5xx: ${res.statusCode}`);
        reject(JSON.stringify(dummyResponseData));
      }

helpers/http.js:103

  • Same issue as httpGET(): after reject() on 429/4xx/5xx, the function continues to process the response body and will attempt resolve(body) on end. Return immediately after reject to avoid extra work and confusing execution flow.
      // 429 throttle is treated as a server error so failTrust is respected
      if (res.statusCode === 429) {
        console.error(`[CH] API 429: throttled`);
        reject(JSON.stringify(dummyResponseData));
      } else if (res.statusCode >= 400 && res.statusCode < 500) {
        console.error(`[CH] API 4xx: ${res.statusCode}`);
        reject(JSON.stringify(clientErrorResponseData));
      } else if (res.statusCode < 200 || res.statusCode >= 300) {
        console.error(`[CH] API 5xx: ${res.statusCode}`);
        reject(JSON.stringify(dummyResponseData));
      }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread handlerViewerRequest.js
@luke-owen-crowdhandler luke-owen-crowdhandler merged commit 6a42b67 into master Jun 11, 2026
1 check passed
@luke-owen-crowdhandler luke-owen-crowdhandler deleted the maintenance/throttle-special-treatment branch June 11, 2026 15:54
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