fix(invoice): fixed pdf generation condition race
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-09-30 15:28:34 +02:00
parent 54fa419255
commit 26df12a70a
2 changed files with 3 additions and 9 deletions

View File

@ -75,16 +75,11 @@ module.exports = Self => {
if (tx) await tx.commit();
const writeStream = fs.createWriteStream(fileSrc);
writeStream.on('open', () => {
response.pipe(writeStream);
});
writeStream.on('open', () => response.pipe(writeStream));
writeStream.on('finish', () => writeStream.end());
return new Promise(resolve => {
writeStream.on('finish', () => {
writeStream.end();
resolve(invoiceOut);
});
writeStream.on('close', () => resolve(invoiceOut));
});
} catch (e) {
if (tx) await tx.rollback();

View File

@ -70,7 +70,6 @@ module.exports = Self => {
let stream = fs.createReadStream(file.path);
return [stream, file.contentType, `filename="${file.name}"`];
} catch (error) {
console.log(error);
if (error.code === 'ENOENT')
throw new UserError('The PDF document does not exists');