@@ -57,6 +57,15 @@ module.exports = (options, req, res, next) => {
5757 } = options . useTempFiles
5858 ? tempFileHandler ( options , field , filename ) // Upload into temporary file.
5959 : memHandler ( options , field , filename ) ; // Upload into RAM.
60+
61+ const writePromise = options . useTempFiles
62+ ? getWritePromise ( ) . catch ( err => {
63+ req . unpipe ( busboy ) ;
64+ req . resume ( ) ;
65+ cleanup ( ) ;
66+ next ( err ) ;
67+ } ) : getWritePromise ( ) ;
68+
6069 // Define upload timer.
6170 const uploadTimer = new UploadTimer ( options . uploadTimeout , ( ) => {
6271 file . removeAllListeners ( 'data' ) ;
@@ -114,7 +123,7 @@ module.exports = (options, req, res, next) => {
114123 if ( ! req [ waitFlushProperty ] ) {
115124 req [ waitFlushProperty ] = [ ] ;
116125 }
117- req [ waitFlushProperty ] . push ( getWritePromise ( ) ) ;
126+ req [ waitFlushProperty ] . push ( writePromise ) ;
118127 } ) ;
119128
120129 file . on ( 'error' , ( err ) => {
@@ -142,10 +151,6 @@ module.exports = (options, req, res, next) => {
142151 . then ( ( ) => {
143152 delete req [ waitFlushProperty ] ;
144153 next ( ) ;
145- } ) . catch ( err => {
146- delete req [ waitFlushProperty ] ;
147- debugLog ( options , `Error while waiting files flush: ${ err } ` ) ;
148- next ( err ) ;
149154 } ) ;
150155 } ) ;
151156
0 commit comments