Fix remaining production readiness issues

This commit is contained in:
gpt-engineer-app[bot]
2025-10-20 12:30:09 +00:00
parent 640fdb11db
commit 4983960138
7 changed files with 158 additions and 91 deletions

View File

@@ -46,17 +46,20 @@ function cleanupExpiredEntries() {
cleanupFailureCount = 0;
}
} catch (error) {
} catch (error: unknown) {
// CRITICAL: Increment failure counter and log detailed error information
cleanupFailureCount++;
const errorMessage = error instanceof Error ? error.message : String(error);
const errorStack = error instanceof Error ? error.stack : 'No stack trace available';
console.error(`[Cleanup Error] Cleanup failed (attempt ${cleanupFailureCount}/${MAX_CLEANUP_FAILURES})`);
console.error(`[Cleanup Error] Error message: ${errorMessage}`);
console.error(`[Cleanup Error] Stack trace: ${errorStack}`);
console.error(`[Cleanup Error] Current map size: ${rateLimitMap.size}`);
console.error('[Cleanup Error]', {
attempt: cleanupFailureCount,
maxAttempts: MAX_CLEANUP_FAILURES,
error: errorMessage,
stack: errorStack,
mapSize: rateLimitMap.size
});
// FALLBACK MECHANISM: If cleanup fails repeatedly, force clear to prevent memory leak
if (cleanupFailureCount >= MAX_CLEANUP_FAILURES) {
@@ -204,7 +207,8 @@ serve(async (req) => {
);
}
console.log('Detecting location for IP:', clientIP);
// PII Note: Do not log full IP addresses in production
console.log('[Location] Detecting location for request');
// Use configurable geolocation service with proper error handling
// Defaults to ip-api.com if not configured
@@ -245,7 +249,11 @@ serve(async (req) => {
measurementSystem
};
console.log('Location detected:', result);
console.log('[Location] Location detected:', {
country: result.country,
countryCode: result.countryCode,
measurementSystem: result.measurementSystem
});
return new Response(
JSON.stringify(result),
@@ -257,14 +265,16 @@ serve(async (req) => {
}
);
} catch (error) {
} catch (error: unknown) {
// Enhanced error logging for better visibility and debugging
const errorMessage = error instanceof Error ? error.message : String(error);
const errorStack = error instanceof Error ? error.stack : 'No stack trace available';
console.error('[Location Detection Error] Request failed');
console.error(`[Location Detection Error] Message: ${errorMessage}`);
console.error(`[Location Detection Error] Stack: ${errorStack}`);
console.error('[Location Detection Error]', {
error: errorMessage,
stack: errorStack,
hasIP: true // IP removed for PII protection
});
// Return default (metric) with 500 status to indicate error occurred
// This allows proper error monitoring while still providing fallback data