refs #5772 Fix for unhandled ENOENT error
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-06-23 22:02:33 +02:00
parent c9f11830a2
commit 665339c8d2
2 changed files with 36 additions and 36 deletions

View File

@ -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;
}
};
};

View File

@ -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);