Skip to content

Commit

Permalink
Fix: Handle resume errors
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Jun 16, 2010
1 parent af57e61 commit c9df5fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/formidable/incoming_form.js
Expand Up @@ -36,7 +36,13 @@ IncomingForm.prototype.parse = function(req, cb) {
};

this.resume = function() {
req.resume();
try {
req.resume();
} catch (err) {
this._error(err);
return false;
}

return true;
};

Expand Down
13 changes: 13 additions & 0 deletions test/simple/test-incoming-form.js
Expand Up @@ -63,6 +63,19 @@ test(function parse() {
gently.expect(REQ, 'resume');
assert.strictEqual(form.resume(), true);
})();

(function testResumeException() {
var ERR = new Error('dasdsa');
gently.expect(REQ, 'resume', function() {
throw ERR;
});

gently.expect(form, '_error', function(err) {
assert.strictEqual(err, ERR);
});

assert.strictEqual(form.resume(), false);
})();

(function testEmitError() {
var ERR = new Error('something bad happened');
Expand Down

0 comments on commit c9df5fe

Please sign in to comment.