diff --git a/src/index.ts b/src/index.ts index 64b6092..1c3b93b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,7 +90,10 @@ async function validateTurnstile(context: Context) { }); const outcome = await result.json(); - return outcome.success; + return { + success: outcome.success as boolean, + errorCodes: outcome['error-codes'] as string[], + }; } app.get('/scrape', async (context) => { @@ -99,11 +102,15 @@ app.get('/scrape', async (context) => { const turnstileEnabled = Boolean(context.env?.TURNSTILE_ENABLED); if (turnstileEnabled) { - const success = await validateTurnstile(context); + const turnstileResponse = await validateTurnstile(context); - if (!success) { + if (!turnstileResponse.success) { context.status(401); - return context.text('Turnstile invalid'); + return context.text( + `Turnstile invalid, error codes: ${turnstileResponse.errorCodes.join( + ', ', + )}`, + ); } }