refactor(transcription): typed BlockConflictResolvedError instead of prose throw

Felix #3: the 409 path was throwing a human-prose Error which read like
an i18n string that escaped translation. Replace with a named class
carrying code='CONFLICT_RESOLVED' so callers can branch on intent and
future error reporters can map the structured code instead of grepping
strings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-29 01:05:47 +02:00
parent cb51e8e432
commit fd3a44d10c
3 changed files with 45 additions and 3 deletions

View File

@@ -100,7 +100,8 @@ async function saveBlock(
});
if (res.status === 409) {
// Rename-mid-edit (B12b): refetch latest, merge so transcriber input survives.
const { mergeBlockOnConflict } = await import('$lib/utils/blockConflictMerge');
const { mergeBlockOnConflict, BlockConflictResolvedError } =
await import('$lib/utils/blockConflictMerge');
const fresh = await fetch(`/api/documents/${doc.id}/transcription-blocks/${blockId}`);
if (fresh.ok) {
const serverBlock = await fresh.json();
@@ -111,7 +112,7 @@ async function saveBlock(
});
transcriptionBlocks = transcriptionBlocks.map((b) => (b.id === blockId ? merged : b));
}
throw new Error('Conflict resolved — please save again');
throw new BlockConflictResolvedError(blockId);
}
if (!res.ok) throw new Error('Save failed');
const updated = await res.json();