Fix error handling
This commit is contained in:
parent
816690360e
commit
b5e6a341ba
2 changed files with 4 additions and 12 deletions
|
|
@ -5,7 +5,7 @@ import { Transition, TransitionChild, DialogPanel, DialogTitle } from '@headless
|
||||||
import { Fragment, useState } from 'react';
|
import { Fragment, useState } from 'react';
|
||||||
|
|
||||||
export function DocumentList() {
|
export function DocumentList() {
|
||||||
const { documents, removeDocument, isLoading, error } = usePDF();
|
const { documents, removeDocument, isLoading } = usePDF();
|
||||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
||||||
const [documentToDelete, setDocumentToDelete] = useState<{ id: string; name: string } | null>(null);
|
const [documentToDelete, setDocumentToDelete] = useState<{ id: string; name: string } | null>(null);
|
||||||
|
|
||||||
|
|
@ -29,14 +29,6 @@ export function DocumentList() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
|
||||||
return (
|
|
||||||
<div className="w-full text-center text-red-500">
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (documents.length === 0) {
|
if (documents.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="w-full text-center text-muted">
|
<div className="w-full text-center text-muted">
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ interface PDFUploaderProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PDFUploader({ className = '' }: PDFUploaderProps) {
|
export function PDFUploader({ className = '' }: PDFUploaderProps) {
|
||||||
const { addDocument, error: contextError } = usePDF();
|
const { addDocument } = usePDF();
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
const [isUploading, setIsUploading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
@ -21,13 +21,13 @@ export function PDFUploader({ className = '' }: PDFUploaderProps) {
|
||||||
try {
|
try {
|
||||||
await addDocument(file);
|
await addDocument(file);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(contextError || 'Failed to upload PDF. Please try again.');
|
setError('Failed to upload PDF. Please try again.');
|
||||||
console.error('Upload error:', err);
|
console.error('Upload error:', err);
|
||||||
} finally {
|
} finally {
|
||||||
setIsUploading(false);
|
setIsUploading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [addDocument, contextError]);
|
}, [addDocument]);
|
||||||
|
|
||||||
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
||||||
onDrop,
|
onDrop,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue