n8n int cleaning

This commit is contained in:
alma 2025-05-18 09:03:46 +02:00
parent c0c0151439
commit 93d9cc8a78

View File

@ -32,50 +32,69 @@ export class N8nService {
throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`); throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`);
} }
const result = await response.json(); // Handle allEntries format
console.log('Received response from n8n:', JSON.stringify(result, null, 2)); const responseText = await response.text();
console.log('Raw response from n8n:', responseText);
// Handle lastNodeJson format try {
if (result.lastNodeJson) { // Try to parse as JSON first
try { const result = JSON.parse(responseText);
const parsedResults = JSON.parse(result.lastNodeJson); console.log('Parsed JSON response:', JSON.stringify(result, null, 2));
return {
success: true, // Handle lastNodeJson format
results: { if (result.lastNodeJson) {
leantimeProjectId: parsedResults.leantimeProjectId?.toString() || null, try {
outlineCollectionId: parsedResults.outlineCollectionId?.toString() || null, const parsedResults = JSON.parse(result.lastNodeJson);
rocketChatChannelId: parsedResults.rocketChatChannelId?.toString() || null, return {
giteaRepositoryUrl: parsedResults.giteaRepositoryUrl || null success: true,
} results: {
}; leantimeProjectId: parsedResults.leantimeProjectId?.toString() || null,
} catch (parseError) { outlineCollectionId: parsedResults.outlineCollectionId?.toString() || null,
console.error('Error parsing lastNodeJson:', parseError); rocketChatChannelId: parsedResults.rocketChatChannelId?.toString() || null,
return { giteaRepositoryUrl: parsedResults.giteaRepositoryUrl || null
success: false, }
error: 'Failed to parse n8n response', };
results: { } catch (parseError) {
leantimeProjectId: null, console.error('Error parsing lastNodeJson:', parseError);
outlineCollectionId: null, return {
rocketChatChannelId: null, success: false,
giteaRepositoryUrl: null error: 'Failed to parse n8n response',
} results: {
}; leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
};
}
} }
// Handle regular JSON response
const integrationResults = result.results || result;
console.log('Integration results:', JSON.stringify(integrationResults, null, 2));
return {
success: true,
results: {
leantimeProjectId: integrationResults.leantimeProjectId?.toString() || null,
outlineCollectionId: integrationResults.outlineCollectionId?.toString() || null,
rocketChatChannelId: integrationResults.rocketChatChannelId?.toString() || null,
giteaRepositoryUrl: integrationResults.giteaRepositoryUrl || null
}
};
} catch (parseError) {
console.error('Error parsing response:', parseError);
// If parsing fails, return a default success response
return {
success: true,
results: {
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
};
} }
// Handle regular JSON response
const integrationResults = result.results || result;
console.log('Integration results:', JSON.stringify(integrationResults, null, 2));
return {
success: true,
results: {
leantimeProjectId: integrationResults.leantimeProjectId?.toString() || null,
outlineCollectionId: integrationResults.outlineCollectionId?.toString() || null,
rocketChatChannelId: integrationResults.rocketChatChannelId?.toString() || null,
giteaRepositoryUrl: integrationResults.giteaRepositoryUrl || null
}
};
} catch (error) { } catch (error) {
console.error('Error triggering n8n workflow:', error); console.error('Error triggering n8n workflow:', error);
return { return {