diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index cb9e211b..84b74069 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -209,12 +209,18 @@ export async function POST(request: Request) { }; try { + console.log('Sending data to n8n workflow:', { + ...n8nData, + password: undefined // Don't log sensitive data + }); + const workflowResult = await n8nService.triggerMissionCreation(n8nData); if (!workflowResult.success) { + console.error('n8n workflow failed:', workflowResult.error); return NextResponse.json({ error: 'Failed to create mission resources', - details: workflowResult.error, + details: workflowResult.error || 'The mission creation process failed', code: 'WORKFLOW_ERROR' }, { status: 500 }); } @@ -222,6 +228,21 @@ export async function POST(request: Request) { return NextResponse.json(workflowResult); } catch (error) { console.error('Error triggering n8n workflow:', error); + + // Check if it's an n8n workflow error + if (error instanceof Error && error.message.includes('HTTP error! status: 500')) { + return NextResponse.json( + { + error: 'Mission creation workflow failed', + details: 'The mission creation process encountered an error. Please try again later.', + code: 'WORKFLOW_ERROR', + originalError: error.message + }, + { status: 500 } + ); + } + + // Handle other types of errors return NextResponse.json( { error: 'Failed to create mission resources',