Skip to content

Commit f0fd6e7

Browse files
committed
fix: add timeout and error handling to cv-process route
- Add 60-second timeout to prevent hanging API calls - Add proper error handling and logging for debugging - Browser was getting 404 because startProcessing was hanging indefinitely - This will either complete successfully or fail with proper error response
1 parent ddf7230 commit f0fd6e7

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

frontend/src/app/api/cv-process/route.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ export async function POST(request: Request) {
2929

3030
console.log('✅ [DEBUG] About to call startProcessing');
3131

32-
// Use the reusable processing function
33-
return startProcessing(
32+
try {
33+
// Use the reusable processing function with timeout
34+
const processingPromise = startProcessing(
3435
applicant_id,
3536
'cv_status',
3637
async (applicant) => {
@@ -97,4 +98,22 @@ export async function POST(request: Request) {
9798
},
9899
'CV'
99100
);
101+
102+
// Add timeout to prevent hanging
103+
const timeoutPromise = new Promise<never>((_, reject) => {
104+
setTimeout(() => reject(new Error('CV processing timeout after 60 seconds')), 60000);
105+
});
106+
107+
const result = await Promise.race([processingPromise, timeoutPromise]);
108+
console.log('✅ [DEBUG] CV processing completed successfully');
109+
return result;
110+
111+
} catch (error) {
112+
console.error('❌ [DEBUG] CV processing failed:', error);
113+
return NextResponse.json({
114+
success: false,
115+
error: error instanceof Error ? error.message : 'CV processing failed',
116+
applicant_id: applicant_id
117+
}, { status: 500 });
118+
}
100119
}

0 commit comments

Comments
 (0)