mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-20 20:48:11 -05:00
Compare commits
3 Commits
testing-cl
...
add-debugg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f8bcff2f4 | ||
|
|
7b938e918c | ||
|
|
38299877c2 |
@@ -113,13 +113,39 @@ export function Turnstile({
|
|||||||
widgetIdRef.current = window.turnstile.render(containerRef.current, {
|
widgetIdRef.current = window.turnstile.render(containerRef.current, {
|
||||||
sitekey: siteKey,
|
sitekey: siteKey,
|
||||||
callback: (token: string) => {
|
callback: (token: string) => {
|
||||||
|
console.log("[Turnstile] Verification successful");
|
||||||
onVerify(token);
|
onVerify(token);
|
||||||
},
|
},
|
||||||
"expired-callback": () => {
|
"expired-callback": () => {
|
||||||
|
console.warn("[Turnstile] Token expired");
|
||||||
onExpire?.();
|
onExpire?.();
|
||||||
},
|
},
|
||||||
"error-callback": () => {
|
"error-callback": (errorCode: string) => {
|
||||||
onError?.(new Error("Turnstile widget encountered an error"));
|
// Capture the actual Cloudflare error code for debugging
|
||||||
|
console.error("[Turnstile] Error occurred:", errorCode);
|
||||||
|
|
||||||
|
// Map Cloudflare error codes to user-friendly messages
|
||||||
|
const errorMessages: Record<string, string> = {
|
||||||
|
"110100": "Invalid site configuration. Please contact support.",
|
||||||
|
"110200": "Domain not allowed for this CAPTCHA.",
|
||||||
|
"110201": "Hostname mismatch. Please try refreshing the page.",
|
||||||
|
"110400": "Invalid verification action.",
|
||||||
|
"110500": "Invalid custom data.",
|
||||||
|
"110600": "JavaScript execution error.",
|
||||||
|
"300010": "Session timeout. Please try again.",
|
||||||
|
"300020": "Network error. Please check your connection.",
|
||||||
|
"300030": "Challenge closed by user.",
|
||||||
|
"600010": "Verification timeout. Please try again.",
|
||||||
|
"600020": "Internal error. Please try again later.",
|
||||||
|
};
|
||||||
|
|
||||||
|
const errorMessage =
|
||||||
|
errorMessages[errorCode] ||
|
||||||
|
`Verification failed (Error: ${errorCode}). Please try again.`;
|
||||||
|
|
||||||
|
const error = new Error(errorMessage);
|
||||||
|
(error as any).errorCode = errorCode;
|
||||||
|
onError?.(error);
|
||||||
},
|
},
|
||||||
action,
|
action,
|
||||||
});
|
});
|
||||||
@@ -181,12 +207,13 @@ declare global {
|
|||||||
sitekey: string;
|
sitekey: string;
|
||||||
callback: (token: string) => void;
|
callback: (token: string) => void;
|
||||||
"expired-callback"?: () => void;
|
"expired-callback"?: () => void;
|
||||||
"error-callback"?: () => void;
|
"error-callback"?: (errorCode: string) => void;
|
||||||
action?: string;
|
action?: string;
|
||||||
},
|
},
|
||||||
) => string;
|
) => string;
|
||||||
reset: (widgetId: string) => void;
|
reset: (widgetId: string) => void;
|
||||||
remove: (widgetId: string) => void;
|
remove: (widgetId: string) => void;
|
||||||
|
getResponse: (widgetId: string) => string | undefined;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useState, useCallback, useEffect } from "react";
|
import { useState, useCallback, useEffect } from "react";
|
||||||
|
import * as Sentry from "@sentry/nextjs";
|
||||||
import { verifyTurnstileToken } from "@/lib/turnstile";
|
import { verifyTurnstileToken } from "@/lib/turnstile";
|
||||||
import { environment } from "@/services/environment";
|
import { environment } from "@/services/environment";
|
||||||
|
|
||||||
@@ -156,6 +157,28 @@ export function useTurnstile({
|
|||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
if (shouldRender) {
|
if (shouldRender) {
|
||||||
setError(err);
|
setError(err);
|
||||||
|
|
||||||
|
// Log to Sentry with error code if available
|
||||||
|
const errorCode = (err as any).errorCode;
|
||||||
|
Sentry.captureException(err, {
|
||||||
|
level: "error",
|
||||||
|
extra: {
|
||||||
|
errorCode,
|
||||||
|
action,
|
||||||
|
context: "Turnstile widget error",
|
||||||
|
message: err.message,
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
turnstile_error: errorCode || "unknown",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.error("[useTurnstile] Turnstile error:", {
|
||||||
|
message: err.message,
|
||||||
|
errorCode,
|
||||||
|
action,
|
||||||
|
});
|
||||||
|
|
||||||
if (resetOnError) {
|
if (resetOnError) {
|
||||||
setToken(null);
|
setToken(null);
|
||||||
setVerified(false);
|
setVerified(false);
|
||||||
@@ -163,7 +186,7 @@ export function useTurnstile({
|
|||||||
if (onError) onError(err);
|
if (onError) onError(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[onError, shouldRender, resetOnError],
|
[onError, shouldRender, resetOnError, action],
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user