Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This folder contains the built output assets for the worker "crowdhandler-integration" generated at 2026-06-09T11:27:13.384Z.
This folder contains the built output assets for the worker "crowdhandler-integration" generated at 2026-06-10T15:07:39.514Z.
15 changes: 14 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion helpers/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const dummyResponseData = {
},
}

// Client error response (4xx) - never triggers failTrust, always safety net
// Client error response (4xx, excluding 429) - never triggers failTrust, always safety net
const clientErrorResponseData = {
result: {
status: 2,
Expand Down Expand Up @@ -57,6 +57,10 @@ const http_helpers = {
responseObject.statusText = "Communication failure between Cloudflare and the CrowdHandler API occurred."
responseObject.success = false
return responseObject;
//Communication success. 429 throttle returned. Treated as a server error so failTrust is respected.
} else if (fetchResponse.status === 429) {
console.error(`[CH] API 429: throttled`)
responseObject.body = dummyResponseData
//Communication success. 4xx client error returned.
} else if (fetchResponse.status >= 400 && fetchResponse.status < 500) {
console.error(`[CH] API 4xx: ${fetchResponse.status}`)
Expand Down
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,19 @@ async function handleRequest(request, env, ctx) {
let redirectLocation
let statusCode

//Normal healthy response
if (responseBody.promoted !== 1 && responseBody.status !== 2) {
//Throttle response (status 6) - treated as a server error, respect failTrust setting
if (responseBody.status === 6 && failTrust === true) {
redirect = false
} else if (responseBody.status === 6) {
console.error('[CH] API throttle response (status 6) - redirecting to safety net')
redirect = true
if (safetyNetSlug) {
redirectLocation = `https://${waitingRoomDomain}/${safetyNetSlug}?url=${targetURL}&ch-code=${chCode}&ch-id=${responseBody.token}&ch-public-key=${env.API_KEY}`
} else {
redirectLocation = `https://${waitingRoomDomain}/?url=${targetURL}&ch-code=${chCode}&ch-id=${responseBody.token}&ch-public-key=${env.API_KEY}`
}
Comment thread
luke-owen-crowdhandler marked this conversation as resolved.
//Normal healthy response
} else if (responseBody.promoted !== 1 && responseBody.status !== 2) {
redirect = true
redirectLocation = `https://${waitingRoomDomain}/${responseBody.slug}?url=${targetURL}&ch-code=${chCode}&ch-id=${responseBody.token}&ch-public-key=${env.API_KEY}`
//4xx client error - always redirect to safety net (ignore failTrust)
Expand Down