This commit is contained in:
parent
c9f11830a2
commit
665339c8d2
|
@ -42,7 +42,6 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
try {
|
||||
const invoiceOut = await models.InvoiceOut.findById(id, {
|
||||
fields: ['ref', 'issued']
|
||||
}, myOptions);
|
||||
|
@ -70,14 +69,15 @@ module.exports = Self => {
|
|||
await Self.createPdf(ctx, id, myOptions);
|
||||
}
|
||||
|
||||
const stream = fs.createReadStream(file.path);
|
||||
const stream = await fs.createReadStream(file.path);
|
||||
// XXX: To prevent unhandled ENOENT error
|
||||
// https://stackoverflow.com/questions/17136536/is-enoent-from-fs-createreadstream-uncatchable
|
||||
stream.on('error', err => {
|
||||
const e = new Error(err.message);
|
||||
err.stack = e.stack;
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
return [stream, file.contentType, `filename="${file.name}"`];
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT')
|
||||
throw new UserError('The PDF document does not exist');
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -63,12 +63,12 @@ class Email extends Component {
|
|||
await getAttachments(componentPath, component.attachments);
|
||||
|
||||
if (component.components)
|
||||
await getSubcomponentAttachments(component)
|
||||
await getSubcomponentAttachments(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await getSubcomponentAttachments(instance)
|
||||
await getSubcomponentAttachments(instance);
|
||||
|
||||
if (this.attachments)
|
||||
await getAttachments(this.path, this.attachments);
|
||||
|
|
Loading…
Reference in New Issue