feat(preview): improve failure recovery and configuration
Update the client-side preview status logic to gracefully handle failed states and return fallback URLs. Add PDF worker tracing to the build configuration for preview-related API endpoints and include server-side error logging.
This commit is contained in:
parent
deaacbd6f0
commit
596c04d4d3
3 changed files with 26 additions and 2 deletions
|
|
@ -17,6 +17,15 @@ const nextConfig: NextConfig = {
|
|||
'/api/whisper': [
|
||||
'./node_modules/ffmpeg-static/ffmpeg',
|
||||
],
|
||||
'/api/documents/blob/preview/ensure': [
|
||||
'./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs',
|
||||
],
|
||||
'/api/documents/blob/preview/presign': [
|
||||
'./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs',
|
||||
],
|
||||
'/api/documents/blob/preview/fallback': [
|
||||
'./node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -328,10 +328,24 @@ export async function getDocumentPreviewStatus(
|
|||
};
|
||||
}
|
||||
|
||||
// Handle failed preview generation (500 with status: 'failed')
|
||||
const contentType = res.headers.get('content-type') || '';
|
||||
if (contentType.includes('application/json')) {
|
||||
const data = (await res.json().catch(() => null)) as { error?: string } | null;
|
||||
throw new Error(data?.error || `Failed to load preview status (status ${res.status})`);
|
||||
const data = (await res.json().catch(() => null)) as {
|
||||
status?: string;
|
||||
lastError?: string;
|
||||
error?: string;
|
||||
} | null;
|
||||
if (data?.status === 'failed') {
|
||||
return {
|
||||
kind: 'pending',
|
||||
status: 'failed',
|
||||
retryAfterMs: 0,
|
||||
fallbackUrl: documentPreviewFallbackUrl(id),
|
||||
presignUrl: documentPreviewPresignUrl(id),
|
||||
};
|
||||
}
|
||||
throw new Error(data?.error || data?.lastError || `Failed to load preview status (status ${res.status})`);
|
||||
}
|
||||
|
||||
throw new Error(`Failed to load preview status (status ${res.status})`);
|
||||
|
|
|
|||
|
|
@ -388,6 +388,7 @@ export async function ensureDocumentPreview(doc: PreviewSourceDocument, namespac
|
|||
eTag: head.eTag,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`[document-previews] Preview generation failed for ${doc.id} (type=${doc.type}):`, error);
|
||||
await markPreviewFailed(doc.id, namespaceKey, error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue