Skip to content
Open
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
1 change: 1 addition & 0 deletions src/DocViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface DocViewerProps {
language?: AvailableLanguages;
activeDocument?: IDocument;
onDocumentChange?: (document: IDocument) => void;
onFetchError?: (error: Error) => void;
}

const DocViewer = forwardRef<DocViewerRef, DocViewerProps>((props, ref) => {
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useDocumentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const useDocumentLoader = (): {
CurrentRenderer: DocRenderer | null | undefined;
} => {
const { state, dispatch } = useContext(DocViewerContext);
const { currentFileNo, currentDocument, prefetchMethod } = state;
const { currentFileNo, currentDocument, prefetchMethod, onFetchError } = state;

const { CurrentRenderer } = useRendererSelector();

Expand Down Expand Up @@ -56,7 +56,11 @@ export const useDocumentLoader = (): {
})
.catch((error) => {
if (error?.name !== "AbortError") {
throw error;
if (onFetchError) {
onFetchError(error);
} else {
throw error;
}
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/store/DocViewerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const DocViewerProvider = forwardRef<
language,
activeDocument,
onDocumentChange,
onFetchError,
} = props;

const [state, dispatch] = useReducer<MainStateReducer>(mainStateReducer, {
Expand All @@ -66,6 +67,7 @@ const DocViewerProvider = forwardRef<
language: language && locales[language] ? language : defaultLanguage,
activeDocument,
onDocumentChange,
onFetchError,
});

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/store/mainStateReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type IMainState = {
language: AvailableLanguages;
activeDocument?: IDocument;
onDocumentChange?: (document: IDocument) => void;
onFetchError?: (error: Error) => void;
};

export const initialState: IMainState = {
Expand Down