diff --git a/app/api/missions/route.ts b/app/api/missions/route.ts index d242efc7..5ed91ac4 100644 --- a/app/api/missions/route.ts +++ b/app/api/missions/route.ts @@ -187,12 +187,12 @@ export async function POST(request: Request) { }); // Update the existing mission with new integration IDs - const updateData: Prisma.MissionUncheckedUpdateInput = { + const updateData = { rocketChatChannelId: body.rocketchatChannelId || existingMission.rocketChatChannelId, leantimeProjectId: body.leantimeProjectId || existingMission.leantimeProjectId, outlineCollectionId: body.documentationCollectionId || existingMission.outlineCollectionId, giteaRepositoryUrl: body.gitRepoUrl || existingMission.giteaRepositoryUrl - }; + } as any; const updatedMission = await prisma.mission.update({ where: { id: existingMission.id }, @@ -230,7 +230,10 @@ export async function POST(request: Request) { if (!workflowResult.success) { console.error('N8n workflow failed:', workflowResult.error); - return NextResponse.json({ error: 'Failed to create mission resources' }, { status: 500 }); + return NextResponse.json({ + error: 'Failed to create mission resources', + details: workflowResult.error + }, { status: 500 }); } // Process workflow results @@ -306,8 +309,23 @@ export async function POST(request: Request) { return NextResponse.json(mission); } catch (error) { console.error('Error in n8n workflow:', error); + // If there's an error, we should clean up any resources that were created + if (error instanceof Error && error.message.includes('HTTP error! status: 500')) { + return NextResponse.json( + { + error: 'Failed to create mission resources', + details: 'The mission creation process failed. Please try again later.', + code: 'WORKFLOW_ERROR' + }, + { status: 500 } + ); + } return NextResponse.json( - { error: 'Failed to create mission resources', details: error instanceof Error ? error.message : String(error) }, + { + error: 'Failed to create mission', + details: error instanceof Error ? error.message : String(error), + code: 'MISSION_CREATION_ERROR' + }, { status: 500 } ); }