mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:31:11 -05:00
Fix remaining console statements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { serve } from "https://deno.land/std@0.190.0/http/server.ts";
|
||||
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.57.4";
|
||||
import { edgeLogger, startRequest, endRequest } from '../_shared/logger.ts';
|
||||
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
@@ -12,10 +13,6 @@ interface EscalationRequest {
|
||||
escalatedBy: string;
|
||||
}
|
||||
|
||||
// Simple request tracking
|
||||
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
|
||||
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
|
||||
|
||||
serve(async (req) => {
|
||||
const tracking = startRequest();
|
||||
|
||||
@@ -31,7 +28,12 @@ serve(async (req) => {
|
||||
|
||||
const { submissionId, escalationReason, escalatedBy }: EscalationRequest = await req.json();
|
||||
|
||||
console.log('Processing escalation notification:', { submissionId, escalationReason, escalatedBy });
|
||||
edgeLogger.info('Processing escalation notification', {
|
||||
requestId: tracking.requestId,
|
||||
submissionId,
|
||||
escalatedBy,
|
||||
action: 'send_escalation'
|
||||
});
|
||||
|
||||
// Fetch submission details
|
||||
const { data: submission, error: submissionError } = await supabase
|
||||
@@ -52,7 +54,11 @@ serve(async (req) => {
|
||||
.single();
|
||||
|
||||
if (escalatorError) {
|
||||
console.error('Failed to fetch escalator profile:', escalatorError);
|
||||
edgeLogger.error('Failed to fetch escalator profile', {
|
||||
requestId: tracking.requestId,
|
||||
error: escalatorError.message,
|
||||
escalatedBy
|
||||
});
|
||||
}
|
||||
|
||||
// Fetch submission items count
|
||||
@@ -62,7 +68,11 @@ serve(async (req) => {
|
||||
.eq('submission_id', submissionId);
|
||||
|
||||
if (countError) {
|
||||
console.error('Failed to fetch items count:', countError);
|
||||
edgeLogger.error('Failed to fetch items count', {
|
||||
requestId: tracking.requestId,
|
||||
error: countError.message,
|
||||
submissionId
|
||||
});
|
||||
}
|
||||
|
||||
// Prepare email content
|
||||
@@ -185,7 +195,10 @@ serve(async (req) => {
|
||||
}),
|
||||
});
|
||||
} catch (fetchError) {
|
||||
console.error('Network error sending email:', fetchError);
|
||||
edgeLogger.error('Network error sending email', {
|
||||
requestId: tracking.requestId,
|
||||
error: fetchError.message
|
||||
});
|
||||
throw new Error('Network error: Unable to reach email service');
|
||||
}
|
||||
|
||||
@@ -196,7 +209,11 @@ serve(async (req) => {
|
||||
} catch (parseError) {
|
||||
errorText = 'Unable to parse error response';
|
||||
}
|
||||
console.error('ForwardEmail API error:', errorText);
|
||||
edgeLogger.error('ForwardEmail API error', {
|
||||
requestId: tracking.requestId,
|
||||
status: emailResponse.status,
|
||||
errorText
|
||||
});
|
||||
throw new Error(`Failed to send email: ${emailResponse.status} - ${errorText}`);
|
||||
}
|
||||
|
||||
@@ -204,10 +221,16 @@ serve(async (req) => {
|
||||
try {
|
||||
emailResult = await emailResponse.json();
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse email API response:', parseError);
|
||||
edgeLogger.error('Failed to parse email API response', {
|
||||
requestId: tracking.requestId,
|
||||
error: parseError.message
|
||||
});
|
||||
throw new Error('Invalid response from email service');
|
||||
}
|
||||
console.log('Email sent successfully:', emailResult);
|
||||
edgeLogger.info('Email sent successfully', {
|
||||
requestId: tracking.requestId,
|
||||
emailId: emailResult.id
|
||||
});
|
||||
|
||||
// Update submission with notification status
|
||||
const { error: updateError } = await supabase
|
||||
@@ -221,11 +244,20 @@ serve(async (req) => {
|
||||
.eq('id', submissionId);
|
||||
|
||||
if (updateError) {
|
||||
console.error('Failed to update submission escalation status:', updateError);
|
||||
edgeLogger.error('Failed to update submission escalation status', {
|
||||
requestId: tracking.requestId,
|
||||
error: updateError.message,
|
||||
submissionId
|
||||
});
|
||||
}
|
||||
|
||||
const duration = endRequest(tracking);
|
||||
console.log('Escalation notification sent', { requestId: tracking.requestId, duration, emailId: emailResult.id });
|
||||
edgeLogger.info('Escalation notification sent', {
|
||||
requestId: tracking.requestId,
|
||||
duration,
|
||||
emailId: emailResult.id,
|
||||
submissionId
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
@@ -242,7 +274,11 @@ serve(async (req) => {
|
||||
);
|
||||
} catch (error) {
|
||||
const duration = endRequest(tracking);
|
||||
console.error('Error in send-escalation-notification:', error, { requestId: tracking.requestId, duration });
|
||||
edgeLogger.error('Error in send-escalation-notification', {
|
||||
requestId: tracking.requestId,
|
||||
duration,
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
});
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
||||
|
||||
Reference in New Issue
Block a user