Commit ab188117 by Edgar HIPP

No more try catch around getValue

parent 1ae98fee
### 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
- 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 {
if (!part.type === "placeholder" || part.module !== moduleName) {
return null;
}
try {
const tagValue = options.scopeManager.getValue(part.value);
if (!tagValue) {
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);
const tagValue = options.scopeManager.getValue(part.value);
if (!tagValue) {
return {value: this.fileTypeConfig.tagTextXml};
}
catch (e) {
const imgBuffer = this.options.getImage(tagValue, part.value);
if (!imgBuffer) {
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) {
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