summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-23 21:31:20 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-23 21:31:20 +0000
commit1a9660a7f204d4098e5dc8809dd33c433d0571bc (patch)
tree536a509ba831fd4e2f1393f731b06d541a5d33a0 /lib
parent35bf2bbed6bae48ff87fcf3f39d176060ef95866 (diff)
Throw exception immediately when document filename is not found
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/docx-reader.js28
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js
index 898da1d..9570dd5 100644
--- a/lib/docx/docx-reader.js
+++ b/lib/docx/docx-reader.js
@@ -61,22 +61,18 @@ function read(docxFile, input) {
};
}).then(function(result) {
var documentFilename = findDocumentFilename(docxFile, result.fileRelationships);
- if (documentFilename) {
- return readXmlFileWithBody(documentFilename, result, function(bodyReader, xml) {
- return result.notes.flatMap(function(notes) {
- return result.comments.flatMap(function(comments) {
- var reader = new DocumentXmlReader({
- bodyReader: bodyReader,
- notes: notes,
- comments: comments
- });
- return reader.convertXmlToDocument(xml);
+ return readXmlFileWithBody(documentFilename, result, function(bodyReader, xml) {
+ return result.notes.flatMap(function(notes) {
+ return result.comments.flatMap(function(comments) {
+ var reader = new DocumentXmlReader({
+ bodyReader: bodyReader,
+ notes: notes,
+ comments: comments
});
+ return reader.convertXmlToDocument(xml);
});
});
- } else {
- throw new Error("Could not find main document part. Are you sure this is a valid .docx file?");
- }
+ });
});
}
@@ -89,7 +85,11 @@ function findDocumentFilename(docxFile, relationships) {
var validTargets = normalisedTargets.filter(function(target) {
return docxFile.exists(target);
});
- return validTargets[0];
+ if (validTargets.length === 0) {
+ throw new Error("Could not find main document part. Are you sure this is a valid .docx file?");
+ } else {
+ return validTargets[0];
+ }
}
function stripPrefix(value, prefix) {