Fix edge function console statements

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 19:09:28 +00:00
parent 7663205512
commit c0f468451f
8 changed files with 92 additions and 64 deletions

View File

@@ -1,7 +1,7 @@
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 { Novu } from "npm:@novu/api@1.6.0";
import { startRequest, endRequest } from "../_shared/logger.ts";
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
@@ -38,7 +38,7 @@ serve(async (req) => {
throw new Error('Action must be either "add" or "remove"');
}
console.log(`${action === 'add' ? 'Adding' : 'Removing'} user ${userId} ${action === 'add' ? 'to' : 'from'} moderator topics`, { requestId: tracking.requestId });
edgeLogger.info(`${action === 'add' ? 'Adding' : 'Removing'} user ${userId} ${action === 'add' ? 'to' : 'from'} moderator topics`, { action: 'manage_moderator_topic', requestId: tracking.requestId, userId, operation: action });
const topics = [TOPICS.MODERATION_SUBMISSIONS, TOPICS.MODERATION_REPORTS];
const results = [];
@@ -50,18 +50,24 @@ serve(async (req) => {
await novu.topics.addSubscribers(topicKey, {
subscribers: [userId],
});
console.log(`Added ${userId} to topic ${topicKey}`);
edgeLogger.info('Added user to topic', { action: 'manage_moderator_topic', requestId: tracking.requestId, userId, topicKey });
results.push({ topic: topicKey, action: 'added', success: true });
} else {
// Remove subscriber from topic
await novu.topics.removeSubscribers(topicKey, {
subscribers: [userId],
});
console.log(`Removed ${userId} from topic ${topicKey}`);
edgeLogger.info('Removed user from topic', { action: 'manage_moderator_topic', requestId: tracking.requestId, userId, topicKey });
results.push({ topic: topicKey, action: 'removed', success: true });
}
} catch (error: any) {
console.error(`Error ${action}ing user ${userId} ${action === 'add' ? 'to' : 'from'} topic ${topicKey}:`, error);
edgeLogger.error(`Error ${action}ing user ${userId} ${action === 'add' ? 'to' : 'from'} topic ${topicKey}`, {
action: 'manage_moderator_topic',
requestId: tracking.requestId,
userId,
topicKey,
error: error.message
});
results.push({
topic: topicKey,
action: action === 'add' ? 'added' : 'removed',
@@ -93,7 +99,7 @@ serve(async (req) => {
}
);
} catch (error: any) {
console.error('Error managing moderator topic:', error);
edgeLogger.error('Error managing moderator topic', { action: 'manage_moderator_topic', requestId: tracking.requestId, error: error.message });
endRequest(tracking, 500, error.message);