From c42714e5f4b643de27b106a084601e39b7e5d04c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 28 Aug 2016 19:44:42 +0100 Subject: Throw more informative error when word/document.xml cannot be found --- lib/docx/docx-reader.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index 57830d7..0c7d57f 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -60,16 +60,20 @@ function read(docxFile, input) { }; }).then(function(result) { return readXmlFileWithBody("document", 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 + if (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 reader.convertXmlToDocument(xml); }); - }); + } else { + throw new Error("Could not find word/document.xml in ZIP file. Are you sure this is a valid .docx file?"); + } }); }); } -- cgit v1.2.3