Skip to content

Commit 7aab28e

Browse files
committed
Add logging when PDF fails to load
1 parent 1801e90 commit 7aab28e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/preprint/[id]/preprint-viewer.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { AuthorsList } from '../../../components'
2121
import { Deposition } from '../../../types/zenodo'
2222
import { fetchDataDeposition, fetchPreprintIdentifier } from '../../../actions'
2323
import ErrorOrTrack from './error-or-track'
24+
import { alertOnError } from '../../../actions/server-utils'
2425

2526
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`
2627

@@ -111,10 +112,6 @@ const PreprintViewer = ({
111112
})
112113
}, [track, preprint.pk, submissionType])
113114

114-
const onDocumentLoadSuccess = (pdf: PDFDocumentProxy): void => {
115-
setPdf(pdf)
116-
}
117-
118115
useEffect(() => {
119116
if (pdf && !hidePdfOutline) {
120117
pdf.getOutline().then(setPdfOutline).catch(console.error)
@@ -201,7 +198,16 @@ const PreprintViewer = ({
201198
<div ref={containerRef} style={{ width: '100%' }}>
202199
<Document
203200
file={preprint.versions[0].public_download_url}
204-
onLoadSuccess={onDocumentLoadSuccess}
201+
onLoadSuccess={(pdf: PDFDocumentProxy) => setPdf(pdf)}
202+
onLoadError={(error) =>
203+
alertOnError({
204+
endpoint: preprint.versions[0].public_download_url,
205+
status: 'n/a',
206+
statusText: 'unknown',
207+
method: 'GET',
208+
apiError: error.message,
209+
})
210+
}
205211
loading={
206212
<Flex
207213
sx={{

0 commit comments

Comments
 (0)