Skip to content

Commit

Permalink
Merge pull request #380 from AdrianSchneider/fixCrashOnTwoErrors
Browse files Browse the repository at this point in the history
Prevent Multiple Errors from Crashing
  • Loading branch information
LinusU authored Dec 14, 2016
2 parents c6fee61 + 2e3d9d8 commit a946f14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/make-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function makeMiddleware (setup) {
}

function abortWithError (uploadError) {
if (errorOccured) return
errorOccured = true

pendingWrites.onceZero(function () {
Expand Down
17 changes: 17 additions & 0 deletions test/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var assert = require('assert')

var os = require('os')
var util = require('./_util')
var multer = require('../')
var stream = require('stream')
Expand Down Expand Up @@ -203,4 +204,20 @@ describe('Error Handling', function () {
done()
})
})

it('should gracefully handle more than one error at a time', function (done) {
var form = new FormData()
var storage = multer.diskStorage({ destination: os.tmpdir() })
var upload = multer({ storage: storage, limits: { fileSize: 1, files: 1 } }).fields([
{ name: 'small0', maxCount: 1 }
])

form.append('small0', util.file('small0.dat'))
form.append('small0', util.file('small0.dat'))

util.submitForm(upload, form, function (err, req) {
assert.equal(err.code, 'LIMIT_FILE_SIZE')
done()
})
})
})

0 comments on commit a946f14

Please sign in to comment.