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
|
const parsedAnnotations = this.pdfManager
|
||||||
.ensure(this, "annotations")
|
.ensure(this, "annotations")
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const annotationRefs = this.annotations;
|
|
||||||
const annotationPromises = [];
|
const annotationPromises = [];
|
||||||
for (let i = 0, ii = annotationRefs.length; i < ii; i++) {
|
for (const annotationRef of this.annotations) {
|
||||||
annotationPromises.push(
|
annotationPromises.push(
|
||||||
AnnotationFactory.create(
|
AnnotationFactory.create(
|
||||||
this.xref,
|
this.xref,
|
||||||
annotationRefs[i],
|
annotationRef,
|
||||||
this.pdfManager,
|
this.pdfManager,
|
||||||
this.idFactory
|
this.idFactory
|
||||||
)
|
).catch(function (reason) {
|
||||||
|
warn(`_parsedAnnotations: "${reason}".`);
|
||||||
|
return null;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(annotationPromises).then(
|
return Promise.all(annotationPromises).then(function (annotations) {
|
||||||
function (annotations) {
|
return annotations.filter(annotation => !!annotation);
|
||||||
return annotations.filter(function isDefined(annotation) {
|
});
|
||||||
return !!annotation;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function (reason) {
|
|
||||||
warn(`_parsedAnnotations: "${reason}".`);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return shadow(this, "_parsedAnnotations", parsedAnnotations);
|
return shadow(this, "_parsedAnnotations", parsedAnnotations);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user