From 698a6e52ee0398aa0b0277781529b06fa082f27b Mon Sep 17 00:00:00 2001 From: alma Date: Mon, 12 May 2025 13:38:28 +0200 Subject: [PATCH] n8n int cleaning --- lib/services/n8n-service.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/services/n8n-service.ts b/lib/services/n8n-service.ts index 8c81d0db..dcdae1be 100644 --- a/lib/services/n8n-service.ts +++ b/lib/services/n8n-service.ts @@ -29,7 +29,8 @@ export class N8nService { const response = await axios.post(this.webhookUrl, missionData, { headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Accept': 'application/json' }, timeout: 30000 // 30 second timeout }); @@ -38,17 +39,37 @@ export class N8nService { status: response.status, statusText: response.statusText, headers: response.headers, - data: response.data + data: response.data, + contentType: response.headers['content-type'] }); // Handle string response 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 { success: true, results: { message: response.data, - // Add default empty integration results leantimeProjectId: null, outlineCollectionId: null, rocketChatChannelId: null, @@ -73,6 +94,7 @@ export class N8nService { // Ensure the response has the expected structure const result = response.data; if (!result.results) { + console.warn('Response missing results object, adding default structure'); result.results = { leantimeProjectId: null, outlineCollectionId: null,