@@ -56,20 +56,38 @@ const handler = {
5656
5757 switch ( decision ) {
5858 case 'block' :
59+ try {
60+ metrics ( request , env , {
61+ decision,
62+ cached : decisionCached || false ,
63+ ruleId : remediationResult . ruleId || '' ,
64+ } ) ;
5965 if ( env . MODE != 'block' ) {
6066 return fetch ( request ) ;
6167 }
62- metrics ( request , env , { decision, cached : decisionCached || false , score : remediationResult . score || 0 } ) ;
6368 console . log ( JSON . stringify ( { ipAddress : clientIP , remediation : decision , remediationCached : decisionCached || false } ) ) ;
64- const assetResponse = await env . ASSETS . fetch ( new URL ( 'block.html' , request . url ) ) ;
65- return assetResponse ;
69+ const assetResponse = await env . ASSETS . fetch ( new URL ( 'block.html' , request . url ) ) ;
70+ return assetResponse ;
71+ } catch ( error ) {
72+ console . warn ( 'Something went wrong with the block:' , error ) ;
73+ return fetch ( request ) ;
74+ }
6675 case 'captcha' :
76+ try {
77+ metrics ( request , env , {
78+ decision,
79+ cached : decisionCached || false ,
80+ ruleId : remediationResult . ruleId || '' ,
81+ } ) ;
6782 if ( env . MODE != 'block' ) {
6883 return fetch ( request ) ;
6984 }
70- metrics ( request , env , { decision, cached : decisionCached || false , score : remediationResult . score || 0 } ) ;
7185 console . log ( JSON . stringify ( { ipAddress : clientIP , remediation : decision , remediationCached : decisionCached || false } ) ) ;
7286 return captcha ( request , env ) ;
87+ } catch ( error ) {
88+ console . warn ( 'Something went wrong with the captcha:' , error ) ;
89+ return fetch ( request ) ;
90+ }
7391 default :
7492 log ( request , env ) ;
7593 console . log ( JSON . stringify ( { ipAddress : clientIP , remediation : decision , remediationCached : decisionCached || false } ) ) ;
@@ -89,7 +107,7 @@ export const config: ResolveConfigFn = (env: Env, _trigger) => {
89107
90108 try {
91109 // More explicit check for enabled metrics
92- if ( env . PERFORMANCE_METRICS === 'true' && env . PROMETHEUS_URL ) {
110+ if ( env . PERFORMANCE_METRICS && env . PROMETHEUS_URL ) {
93111 console . log ( 'Enabling OpenTelemetry export to:' , env . PROMETHEUS_URL ) ;
94112 return {
95113 exporter : {
0 commit comments