mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:11:13 -05:00
Add edge function logging
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
|
||||
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2.57.4';
|
||||
import { sanitizeError } from '../_shared/errorSanitizer.ts';
|
||||
import { edgeLogger } from '../_shared/logger.ts';
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
@@ -39,14 +40,14 @@ serve(async (req) => {
|
||||
} = await supabaseClient.auth.getUser();
|
||||
|
||||
if (authError || !user) {
|
||||
console.error('[Export] Authentication failed:', authError);
|
||||
edgeLogger.error('Authentication failed', { action: 'export_auth' });
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Unauthorized', success: false }),
|
||||
{ status: 401, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`[Export] Processing export request for user: ${user.id}`);
|
||||
edgeLogger.info('Processing export request', { action: 'export_start', userId: user.id });
|
||||
|
||||
// Check rate limiting - max 1 export per hour
|
||||
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000).toISOString();
|
||||
@@ -86,7 +87,7 @@ serve(async (req) => {
|
||||
format: 'json'
|
||||
};
|
||||
|
||||
console.log('[Export] Export options:', options);
|
||||
edgeLogger.info('Export options', { action: 'export_options', userId: user.id });
|
||||
|
||||
// Fetch profile data
|
||||
const { data: profile, error: profileError } = await supabaseClient
|
||||
@@ -96,7 +97,7 @@ serve(async (req) => {
|
||||
.single();
|
||||
|
||||
if (profileError) {
|
||||
console.error('[Export] Profile fetch failed:', profileError);
|
||||
edgeLogger.error('Profile fetch failed', { action: 'export_profile' });
|
||||
throw new Error('Failed to fetch profile data');
|
||||
}
|
||||
|
||||
@@ -263,7 +264,7 @@ serve(async (req) => {
|
||||
}
|
||||
}]);
|
||||
|
||||
console.log(`[Export] Export completed successfully for user ${user.id}`);
|
||||
edgeLogger.info('Export completed successfully', { action: 'export_complete', userId: user.id });
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({ success: true, data: exportData }),
|
||||
@@ -278,7 +279,7 @@ serve(async (req) => {
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error('[Export] Error:', error);
|
||||
edgeLogger.error('Export error', { action: 'export_error', error: error instanceof Error ? error.message : String(error) });
|
||||
const sanitized = sanitizeError(error, 'export-user-data');
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user