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
120 changes: 84 additions & 36 deletions dist/crowdhandler.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/crowdhandler.cjs.js.map

Large diffs are not rendered by default.

120 changes: 84 additions & 36 deletions dist/crowdhandler.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/crowdhandler.esm.js.map

Large diffs are not rendered by default.

120 changes: 84 additions & 36 deletions dist/crowdhandler.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/crowdhandler.umd.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/crowdhandler.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/crowdhandler.umd.min.js.map

Large diffs are not rendered by default.

118 changes: 83 additions & 35 deletions dist/gatekeeper/gatekeeper.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/types/gatekeeper/gatekeeper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ export declare class Gatekeeper {
* if (result.error) {
* console.error(`API Error ${result.error.statusCode}: ${result.error.message}`);
* // Note: promoted is still set based on error type
* // 4xx errors: promoted = false
* // 5xx errors: promoted based on trustOnFail setting
* // 4xx errors (excluding 429): promoted = false
* // 429 throttle and 5xx errors: promoted based on trustOnFail setting
* }
*
* @throws {CrowdHandlerError} When SDK configuration fails or network errors occur
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crowdhandler-sdk",
"version": "2.4.4",
"version": "2.5.0",
"description": "",
"homepage": "https://www.crowdhandler.com",
"repository": {
Expand Down
86 changes: 69 additions & 17 deletions src/gatekeeper/gatekeeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,8 +1382,8 @@ export class Gatekeeper {
* if (result.error) {
* console.error(`API Error ${result.error.statusCode}: ${result.error.message}`);
* // Note: promoted is still set based on error type
* // 4xx errors: promoted = false
* // 5xx errors: promoted based on trustOnFail setting
* // 4xx errors (excluding 429): promoted = false
* // 429 throttle and 5xx errors: promoted based on trustOnFail setting
Comment on lines 1383 to +1386
* }
*
* @throws {CrowdHandlerError} When SDK configuration fails or network errors occur
Expand Down Expand Up @@ -1444,7 +1444,7 @@ export class Gatekeeper {
const errorMessage = this.options.testError.message || `Simulated error with status ${statusCode}`;

// Apply same logic as real errors
if (statusCode >= 400 && statusCode < 500) {
if (statusCode >= 400 && statusCode < 500 && statusCode !== 429) {
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand Down Expand Up @@ -1519,14 +1519,14 @@ export class Gatekeeper {
const errorMessage = this.sessionStatus?.result?.error || `API request failed with status ${status}`;

// Determine promoted based on error type
if (status && status >= 400 && status < 500) {
// Client errors (4xx) - never promote
if (status && status >= 400 && status < 500 && status !== 429) {
// Client errors (4xx, excluding 429) - never promote
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
} else {
// Server errors (5xx) or other errors - respect trustOnFail
// Server errors (5xx), 429 throttle, or other errors - respect trustOnFail
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand All @@ -1544,6 +1544,19 @@ export class Gatekeeper {
}
}

// Throttle response (status 6) - treated as a server error, respect trustOnFail
if (this.sessionStatus?.result?.status === 6) {
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
result.error = {
message: 'API throttle response (status 6)',
code: 'RATE_LIMITED'
};
Comment on lines +1553 to +1556
return result;
}

// Processing based on promotion status
if (this.sessionStatus) {
const { promoted, slug, token, responseID, deployment, hash, requested, domain } = this.sessionStatus.result;
Expand Down Expand Up @@ -1624,7 +1637,7 @@ export class Gatekeeper {
const errorMessage = this.options.testError.message || `Simulated error with status ${statusCode}`;

// Apply same logic as real errors
if (statusCode >= 400 && statusCode < 500) {
if (statusCode >= 400 && statusCode < 500 && statusCode !== 429) {
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand Down Expand Up @@ -1699,14 +1712,14 @@ export class Gatekeeper {
const errorMessage = this.sessionStatus?.result?.error || `API request failed with status ${status}`;

// Determine promoted based on error type
if (status && status >= 400 && status < 500) {
// Client errors (4xx) - never promote
if (status && status >= 400 && status < 500 && status !== 429) {
// Client errors (4xx, excluding 429) - never promote
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
} else {
// Server errors (5xx) or other errors - respect trustOnFail
// Server errors (5xx), 429 throttle, or other errors - respect trustOnFail
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand All @@ -1724,6 +1737,19 @@ export class Gatekeeper {
}
}

// Throttle response (status 6) - treated as a server error, respect trustOnFail
if (this.sessionStatus?.result?.status === 6) {
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
result.error = {
message: 'API throttle response (status 6)',
code: 'RATE_LIMITED'
};
Comment on lines +1746 to +1749
return result;
}

// Processing based on promotion status
if (this.sessionStatus) {
const { promoted, slug, token, responseID, deployment, hash, requested, domain } = this.sessionStatus.result;
Expand Down Expand Up @@ -1806,7 +1832,7 @@ export class Gatekeeper {
const errorMessage = this.options.testError.message || `Simulated error with status ${statusCode}`;

// Apply same logic as real errors
if (statusCode >= 400 && statusCode < 500) {
if (statusCode >= 400 && statusCode < 500 && statusCode !== 429) {
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand Down Expand Up @@ -1953,14 +1979,14 @@ export class Gatekeeper {
const errorMessage = this.sessionStatus?.result?.error || `API request failed with status ${status}`;

// Determine promoted based on error type
if (status && status >= 400 && status < 500) {
// Client errors (4xx) - never promote
if (status && status >= 400 && status < 500 && status !== 429) {
// Client errors (4xx, excluding 429) - never promote
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
} else {
// Server errors (5xx) or other errors - respect trustOnFail
// Server errors (5xx), 429 throttle, or other errors - respect trustOnFail
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand All @@ -1980,6 +2006,19 @@ export class Gatekeeper {

let token: string;

// Throttle response (status 6) - treated as a server error, respect trustOnFail
if (this.sessionStatus && this.sessionStatus.result.status === 6) {
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
result.error = {
message: 'API throttle response (status 6)',
code: 'RATE_LIMITED'
};
Comment on lines +2015 to +2018
return result;
}

// Pass domain from API response if available
if (this.sessionStatus && this.sessionStatus.result.domain) {
result.domain = this.sessionStatus.result.domain;
Expand Down Expand Up @@ -2065,14 +2104,14 @@ export class Gatekeeper {
const errorMessage = this.sessionStatus?.result?.error || `API request failed with status ${status}`;

// Determine promoted based on error type
if (status && status >= 400 && status < 500) {
// Client errors (4xx) - never promote
if (status && status >= 400 && status < 500 && status !== 429) {
// Client errors (4xx, excluding 429) - never promote
result.promoted = false;
if (this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
} else {
// Server errors (5xx) or other errors - respect trustOnFail
// Server errors (5xx), 429 throttle, or other errors - respect trustOnFail
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
Expand All @@ -2090,6 +2129,19 @@ export class Gatekeeper {
}
}

// Throttle response (status 6) - treated as a server error, respect trustOnFail
if (this.sessionStatus && this.sessionStatus.result.status === 6) {
result.promoted = this.options.trustOnFail;
if (!this.options.trustOnFail && this.options.fallbackSlug) {
result.slug = this.options.fallbackSlug;
}
result.error = {
message: 'API throttle response (status 6)',
code: 'RATE_LIMITED'
};
Comment on lines +2138 to +2141
return result;
}

// Pass domain from API response if available
if (this.sessionStatus && this.sessionStatus.result.domain) {
result.domain = this.sessionStatus.result.domain;
Expand Down