Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/features/projects/components/ExportProjectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const ExportProjectDialog: React.FC<ExportProjectDialogProps> = ({

onClose();
} catch (err) {
setError('Export Failed');
setError(err instanceof Error ? err.message : 'Export Failed');
Logger.logException(err, {
context: 'Export failed',
projectUnitId,
Expand Down
18 changes: 17 additions & 1 deletion src/features/projects/hooks/useExportUsfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,32 @@ interface ExportUsfmPayload {
bookIds: number[];
}

const DEFAULT_EXPORT_ERROR = 'Failed to export USFM';

// The export endpoint streams a ZIP on success and returns a JSON error body
// otherwise. Surface the server's message (supports both the `{ message }`
// envelope and the USFM route's `{ error }` shape) so the dialog can show
// something actionable instead of a generic failure.
const parseExportError = async (response: Response): Promise<string> => {
try {
const data = (await response.json()) as { message?: string; error?: string };
return data.message ?? data.error ?? DEFAULT_EXPORT_ERROR;
} catch {
return DEFAULT_EXPORT_ERROR;
}
};

const exportUsfmRequest = async (payload: ExportUsfmPayload): Promise<Blob> => {
const { projectUnitId, bookIds } = payload;

const response = await fetch(`${config.api.url}/project-units/${projectUnitId}/usfm`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ bookIds }),
});

if (!response.ok) throw new Error('Failed to export USFM');
if (!response.ok) throw new Error(await parseExportError(response));

return response.blob();
};
Expand Down
Loading