Handle errors individually for each annotation in the _parsedAnnotations
getter
While working on PR 11872, it occurred to me that it probably wouldn't be a bad idea to change the `_parsedAnnotations` getter to handle errors individually for each annotation. This way, one broken/corrupt annotation won't prevent the rest of them from being e.g. fetched through the API.
This commit is contained in:
parent
7823d593f9
commit
73636e052a
@ -393,30 +393,24 @@ class Page {
|
||||
const parsedAnnotations = this.pdfManager
|
||||
.ensure(this, "annotations")
|
||||
.then(() => {
|
||||
const annotationRefs = this.annotations;
|
||||
const annotationPromises = [];
|
||||
for (let i = 0, ii = annotationRefs.length; i < ii; i++) {
|
||||
for (const annotationRef of this.annotations) {
|
||||
annotationPromises.push(
|
||||
AnnotationFactory.create(
|
||||
this.xref,
|
||||
annotationRefs[i],
|
||||
annotationRef,
|
||||
this.pdfManager,
|
||||
this.idFactory
|
||||
)
|
||||
).catch(function (reason) {
|
||||
warn(`_parsedAnnotations: "${reason}".`);
|
||||
return null;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.all(annotationPromises).then(
|
||||
function (annotations) {
|
||||
return annotations.filter(function isDefined(annotation) {
|
||||
return !!annotation;
|
||||
});
|
||||
},
|
||||
function (reason) {
|
||||
warn(`_parsedAnnotations: "${reason}".`);
|
||||
return [];
|
||||
}
|
||||
);
|
||||
return Promise.all(annotationPromises).then(function (annotations) {
|
||||
return annotations.filter(annotation => !!annotation);
|
||||
});
|
||||
});
|
||||
|
||||
return shadow(this, "_parsedAnnotations", parsedAnnotations);
|
||||
|
Loading…
Reference in New Issue
Block a user