feat: report skipped duplicates in the upload tray
A book whose files were all already stored settles as skipped rather than done, naming the book that holds them and offering to add it anyway.
This commit is contained in:
@@ -50,6 +50,22 @@
|
||||
toast.error(`${file.name} was not added`, { description: reason });
|
||||
};
|
||||
|
||||
/**
|
||||
* The API's own words, when it has any.
|
||||
*
|
||||
* Adding a file the library already holds under another book is refused with a
|
||||
* 409 naming it — far more use than "failed to add files". SvelteKit hands an
|
||||
* `error()` back as an HttpError on the client, so the message sits on `body`.
|
||||
*/
|
||||
function apiMessage(error: unknown): string | undefined {
|
||||
if (typeof error !== 'object' || error === null) return undefined;
|
||||
|
||||
const body = (error as { body?: { message?: string } }).body;
|
||||
if (typeof body?.message === 'string') return body.message;
|
||||
|
||||
return error instanceof Error ? error.message : undefined;
|
||||
}
|
||||
|
||||
function confirmDelete(file: BookFile) {
|
||||
fileToDelete = file;
|
||||
confirmOpen = true;
|
||||
@@ -148,7 +164,8 @@
|
||||
toast.success('Files added');
|
||||
} catch (error) {
|
||||
console.error('Failed to add files: ', error);
|
||||
toast.error('Failed to add files');
|
||||
toast.error(apiMessage(error) ?? 'Failed to add files');
|
||||
uploadBookFiles.fields.files.set([]);
|
||||
}
|
||||
})}
|
||||
enctype="multipart/form-data"
|
||||
|
||||
Reference in New Issue
Block a user