Treat 429 and status 6 throttle responses as server errors that respe…#15
Merged
luke-owen-crowdhandler merged 1 commit intoJun 11, 2026
Merged
Conversation
…ct failTrust Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
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) inviewerRequest, allowing fail-open whenfailTrust === trueand 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ct failTrust