n8n int cleaning

This commit is contained in:
alma 2025-05-12 13:38:28 +02:00
parent 241fa4455c
commit 698a6e52ee

View File

@ -29,7 +29,8 @@ export class N8nService {
const response = await axios.post(this.webhookUrl, missionData, { const response = await axios.post(this.webhookUrl, missionData, {
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json',
'Accept': 'application/json'
}, },
timeout: 30000 // 30 second timeout timeout: 30000 // 30 second timeout
}); });
@ -38,17 +39,37 @@ export class N8nService {
status: response.status, status: response.status,
statusText: response.statusText, statusText: response.statusText,
headers: response.headers, headers: response.headers,
data: response.data data: response.data,
contentType: response.headers['content-type']
}); });
// Handle string response // Handle string response
if (typeof response.data === 'string') { if (typeof response.data === 'string') {
console.log('Received string response from n8n, treating as success'); console.warn('Received string response from n8n instead of JSON:', {
response: response.data,
contentType: response.headers['content-type'],
webhookUrl: this.webhookUrl
});
// Try to parse the string as JSON if it looks like JSON
if (response.data.trim().startsWith('{') || response.data.trim().startsWith('[')) {
try {
const parsedData = JSON.parse(response.data);
console.log('Successfully parsed string response as JSON:', parsedData);
return {
success: true,
results: parsedData
};
} catch (parseError) {
console.error('Failed to parse string response as JSON:', parseError);
}
}
// If we can't parse it as JSON, return default structure
return { return {
success: true, success: true,
results: { results: {
message: response.data, message: response.data,
// Add default empty integration results
leantimeProjectId: null, leantimeProjectId: null,
outlineCollectionId: null, outlineCollectionId: null,
rocketChatChannelId: null, rocketChatChannelId: null,
@ -73,6 +94,7 @@ export class N8nService {
// Ensure the response has the expected structure // Ensure the response has the expected structure
const result = response.data; const result = response.data;
if (!result.results) { if (!result.results) {
console.warn('Response missing results object, adding default structure');
result.results = { result.results = {
leantimeProjectId: null, leantimeProjectId: null,
outlineCollectionId: null, outlineCollectionId: null,