mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
fix: remove Top K in retrieval testing #770 and if the document parsing fails, the error message returned by the backend is displayed (#782)
### What problem does this PR solve? fix: remove Top K in retrieval testing #770 fix: if the document parsing fails, the error message returned by the backend is displayed. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
18
web/src/components/pdf-previewer/hooks.ts
Normal file
18
web/src/components/pdf-previewer/hooks.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import axios from 'axios';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
export const useCatchDocumentError = (url: string) => {
|
||||
const [error, setError] = useState<string>('');
|
||||
|
||||
const fetchDocument = useCallback(async () => {
|
||||
const { data } = await axios.get(url);
|
||||
if (data.retcode !== 0) {
|
||||
setError(data?.retmsg);
|
||||
}
|
||||
}, [url]);
|
||||
useEffect(() => {
|
||||
fetchDocument();
|
||||
}, [fetchDocument]);
|
||||
|
||||
return error;
|
||||
};
|
||||
@ -14,6 +14,8 @@ import {
|
||||
Popup,
|
||||
} from 'react-pdf-highlighter';
|
||||
|
||||
import FileError from '@/pages/document-viewer/file-error';
|
||||
import { useCatchDocumentError } from './hooks';
|
||||
import styles from './index.less';
|
||||
|
||||
interface IProps {
|
||||
@ -38,6 +40,8 @@ const DocumentPreviewer = ({ chunk, documentId, visible }: IProps) => {
|
||||
const { highlights: state, setWidthAndHeight } = useGetChunkHighlights(chunk);
|
||||
const ref = useRef<(highlight: IHighlight) => void>(() => {});
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
const url = getDocumentUrl();
|
||||
const error = useCatchDocumentError(url);
|
||||
|
||||
const resetHash = () => {};
|
||||
|
||||
@ -55,9 +59,10 @@ const DocumentPreviewer = ({ chunk, documentId, visible }: IProps) => {
|
||||
return (
|
||||
<div className={styles.documentContainer}>
|
||||
<PdfLoader
|
||||
url={getDocumentUrl()}
|
||||
url={url}
|
||||
beforeLoad={<Skeleton active />}
|
||||
workerSrc="/pdfjs-dist/pdf.worker.min.js"
|
||||
errorMessage={<FileError>{error}</FileError>}
|
||||
>
|
||||
{(pdfDocument) => {
|
||||
pdfDocument.getPage(1).then((page) => {
|
||||
|
||||
Reference in New Issue
Block a user