Permalink
Browse files

Catching error thrown by Formidable when incorrect Content-type heade…

…rs are sent.
  • Loading branch information...
1 parent c1d86a0 commit 2ded8762dca369f3b233af397746b8679fbcc3e0 @twentyrogersc committed May 24, 2012
Showing with 8 additions and 5 deletions.
  1. +8 −5 index.js
View
@@ -124,12 +124,15 @@ app.get = function(route, cb) {
app.post = function(route, cb) {
addRoute('POST', route, function(req, res) {
- var form = new formidable.IncomingForm()
- form.parse(req, function(err, fields, files) {
- req.body = fields
- req.files = files
+ var parsed = function(err, body, files) {
+ req.body = body || {}
+ req.files = files || {}
cb(req, res)
- })
+ }
+
+ var form = new formidable.IncomingForm()
+ try { form.parse(req, parsed) }
+ catch(e) { parsed() }
})
return app
}

0 comments on commit 2ded876

Please sign in to comment.