Commit ab188117 by Edgar HIPP

No more try catch around getValue

parent 1ae98fee
### unreleased (master branch) ### unreleased (master branch)
- Breaking : The image module no longer swallows error thrown by `options.getImage` and `options.getSize`. It is the implementors responsibility to not throw any errors, or the error will be passed. You can return a falsy value in getImage to not render an image at all.
### 3.0.2 ### 3.0.2
- Fix issue with PPTX : Before, you had to add to your options : {fileType: "pptx"} in the module options passed as argument in the constructor of the module. Now, the fileType is retrieved from the main docxtemplater. - Fix issue with PPTX : Before, you had to add to your options : {fileType: "pptx"} in the module options passed as argument in the constructor of the module. Now, the fileType is retrieved from the main docxtemplater.
......
...@@ -91,19 +91,17 @@ class ImageModule { ...@@ -91,19 +91,17 @@ class ImageModule {
if (!part.type === "placeholder" || part.module !== moduleName) { if (!part.type === "placeholder" || part.module !== moduleName) {
return null; return null;
} }
try { const tagValue = options.scopeManager.getValue(part.value);
const tagValue = options.scopeManager.getValue(part.value); if (!tagValue) {
if (!tagValue) { return {value: this.fileTypeConfig.tagTextXml};
throw new Error("tagValue is empty");
}
const imgBuffer = this.options.getImage(tagValue, part.value);
const rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer);
const sizePixel = this.options.getSize(imgBuffer, tagValue, part.value);
return this.getRenderedPart(part, rId, sizePixel);
} }
catch (e) { const imgBuffer = this.options.getImage(tagValue, part.value);
if (!imgBuffer) {
return {value: this.fileTypeConfig.tagTextXml}; return {value: this.fileTypeConfig.tagTextXml};
} }
const rId = imgManager.addImageRels(this.getNextImageName(), imgBuffer);
const sizePixel = this.options.getSize(imgBuffer, tagValue, part.value);
return this.getRenderedPart(part, rId, sizePixel);
} }
getRenderedPart(part, rId, sizePixel) { getRenderedPart(part, rId, sizePixel) {
if (isNaN(rId)) { if (isNaN(rId)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment