This commit is contained in:
alma 2025-05-23 10:34:39 +02:00
parent 5fd673cdfb
commit 7298d246c1

View File

@ -225,9 +225,23 @@ export async function POST(request: Request) {
};
try {
// Log the data we're sending (without sensitive info)
console.log('Sending data to n8n workflow:', {
...n8nData,
config: { ...n8nData.config, N8N_API_KEY: '[REDACTED]' } // Don't log sensitive data
name: n8nData.name,
creatorId: n8nData.creatorId,
oddScope: n8nData.oddScope,
niveau: n8nData.niveau,
intention: n8nData.intention?.substring(0, 100) + '...',
missionType: n8nData.missionType,
donneurDOrdre: n8nData.donneurDOrdre,
projection: n8nData.projection,
services: n8nData.services,
participation: n8nData.participation,
profils: n8nData.profils,
hasGuardians: Object.keys(n8nData.guardians).length > 0,
volunteersCount: n8nData.volunteers.length,
hasConfig: true,
configKeys: Object.keys(n8nData.config)
});
const workflowResult = await n8nService.triggerMissionCreation(n8nData);
@ -247,10 +261,23 @@ export async function POST(request: Request) {
// Check if it's an n8n workflow error
if (error instanceof Error && error.message.includes('HTTP error! status: 500')) {
// Try to parse the error message for more details
const errorMatch = error.message.match(/body: ({.*})/);
let errorDetails = 'The mission creation process encountered an error';
if (errorMatch) {
try {
const errorBody = JSON.parse(errorMatch[1]);
errorDetails = errorBody.message || errorDetails;
} catch (e) {
console.error('Failed to parse error body:', e);
}
}
return NextResponse.json(
{
error: 'Mission creation workflow failed',
details: 'The mission creation process encountered an error. Please try again later.',
details: errorDetails,
code: 'WORKFLOW_ERROR',
originalError: error.message
},