Browse Source

fix: 对附件写入流进行错误捕捉防止服务停机

lanjianrong 4 years ago
parent
commit
0a6c299754
3 changed files with 12 additions and 0 deletions
  1. 4 0
      app/service/change_att.js
  2. 4 0
      app/service/material_file.js
  3. 4 0
      app/service/stage_att.js

+ 4 - 0
app/service/change_att.js

@@ -92,6 +92,10 @@ module.exports = app => {
                 // 每次开一个新的archiver
                 const ziparchiver = archiver('zip');
                 const outputPath = fs.createWriteStream(path.resolve(this.app.baseDir, zipPath));
+                outputPath.on('error', err => {
+                    reject(err);
+                });
+
                 ziparchiver.pipe(outputPath);
                 files.forEach(item => {
                     ziparchiver.file(path.resolve(this.app.baseDir, item.filepath), { name: item.filename + item.fileext });

+ 4 - 0
app/service/material_file.js

@@ -93,6 +93,10 @@ module.exports = app => {
                 // 每次开一个新的archiver
                 const ziparchiver = archiver('zip');
                 const outputPath = fs.createWriteStream(path.resolve(this.app.baseDir, zipPath));
+                outputPath.on('error', err => {
+                    reject(err);
+                });
+
                 ziparchiver.pipe(outputPath);
                 files.forEach(item => {
                     ziparchiver.file(path.resolve(this.app.baseDir, 'app', item.filepath), { name: item.file_name });

+ 4 - 0
app/service/stage_att.js

@@ -113,6 +113,10 @@ module.exports = app => {
                 // 每次开一个新的archiver
                 const ziparchiver = archiver('zip');
                 const outputPath = fs.createWriteStream(path.resolve(this.app.baseDir, zipPath));
+
+                outputPath.on('error', err => {
+                    reject(err);
+                });
                 ziparchiver.pipe(outputPath);
                 files.forEach(item => {
                     ziparchiver.file(item.filepath, { name: item.filename + item.fileext });