n8n int cleaning

This commit is contained in:
alma 2025-05-18 09:13:12 +02:00
parent 6e29074f5c
commit 88b35ad698
2 changed files with 19 additions and 66 deletions

View File

@ -15,6 +15,17 @@ export class N8nService {
console.log('Triggering n8n workflow with data:', JSON.stringify(data, null, 2)); console.log('Triggering n8n workflow with data:', JSON.stringify(data, null, 2));
console.log('Using webhook URL:', this.webhookUrl); console.log('Using webhook URL:', this.webhookUrl);
// Log the full request details
const requestDetails = {
url: this.webhookUrl,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data
};
console.log('Full request details:', JSON.stringify(requestDetails, null, 2));
const response = await fetch(this.webhookUrl, { const response = await fetch(this.webhookUrl, {
method: 'POST', method: 'POST',
headers: { headers: {
@ -35,69 +46,16 @@ export class N8nService {
const responseText = await response.text(); const responseText = await response.text();
console.log('Raw response from n8n:', responseText); console.log('Raw response from n8n:', responseText);
// Handle 'allEntries' response // Try to parse the response as JSON
if (responseText === 'allEntries') {
console.log('Received allEntries response, workflow triggered successfully');
return {
success: true,
results: {
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
};
}
try { try {
// Try to parse as JSON
const result = JSON.parse(responseText); const result = JSON.parse(responseText);
console.log('Parsed JSON response:', JSON.stringify(result, null, 2)); console.log('Parsed workflow result:', JSON.stringify(result, null, 2));
// Handle lastNodeJson format
if (result.lastNodeJson) {
try {
const parsedResults = JSON.parse(result.lastNodeJson);
return { return {
success: true, success: true,
results: { results: result
leantimeProjectId: parsedResults.leantimeProjectId?.toString() || null,
outlineCollectionId: parsedResults.outlineCollectionId?.toString() || null,
rocketChatChannelId: parsedResults.rocketChatChannelId?.toString() || null,
giteaRepositoryUrl: parsedResults.giteaRepositoryUrl || null
}
}; };
} catch (parseError) { } catch (parseError) {
console.error('Error parsing lastNodeJson:', parseError); console.log('Response is not JSON, treating as workflow trigger confirmation');
return {
success: false,
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 { return {
success: true, success: true,
results: { results: {
@ -112,13 +70,7 @@ export class N8nService {
console.error('Error triggering n8n workflow:', error); console.error('Error triggering n8n workflow:', error);
return { return {
success: false, success: false,
error: error instanceof Error ? error.message : 'Unknown error', error: error instanceof Error ? error.message : 'Unknown error'
results: {
leantimeProjectId: null,
outlineCollectionId: null,
rocketChatChannelId: null,
giteaRepositoryUrl: null
}
}; };
} }
} }

File diff suppressed because one or more lines are too long