feat: add detailed logging for group sync API calls

main
borja (aider) 3 months ago
parent 67bd0a3f94
commit ae8e3fad2b

@ -78,21 +78,49 @@ export class GroupSyncService {
private static async fetchGroupsFromAPI(): Promise<EvolutionGroup[]> {
const url = `${env.EVOLUTION_API_URL}/group/fetchAllGroups/${env.EVOLUTION_API_INSTANCE}?getParticipants=false`;
const response = await fetch(url, {
headers: {
apikey: env.EVOLUTION_API_KEY,
},
console.log(' Fetching groups from API:', {
url: `${url.substring(0, 50)}...`, // Log partial URL for security
communityId: env.WHATSAPP_COMMUNITY_ID,
time: new Date().toISOString()
});
if (!response.ok) {
throw new Error(`API request failed: ${response.statusText}`);
}
try {
const response = await fetch(url, {
headers: {
apikey: env.EVOLUTION_API_KEY,
},
timeout: 120000 // 120 second timeout
});
if (!response.ok) {
const errorBody = await response.text().catch(() => 'Unable to read error body');
console.error('❌ API request failed:', {
status: response.status,
statusText: response.statusText,
headers: Object.fromEntries(response.headers.entries()),
body: errorBody
});
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log(' API response:', {
status: data.status,
message: data.message,
responseLength: data.response?.length || 0
});
const data = await response.json();
if (data.status !== 'success') {
throw new Error(`API error: ${data.message || 'Unknown error'}`);
if (data.status !== 'success') {
throw new Error(`API error: ${data.message || 'Unknown error'}`);
}
return data.response;
} catch (error) {
console.error('❌ Failed to fetch groups:', {
error: error instanceof Error ? error.message : String(error),
stack: error instanceof Error ? error.stack : undefined
});
throw error;
}
return data.response;
}
private static cacheActiveGroups(): void {

Loading…
Cancel
Save