Skip to content

Commit

Permalink
Improved upload error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
cskr committed Jul 15, 2010
1 parent 07d9138 commit 7040a22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions lib/multipart.js
Expand Up @@ -31,18 +31,26 @@ exports.configure = function(config) {
exports.parse = function(context, callback) {
context.params = {};
var req = context.request;
if(new Number(req.headers['content-length']) > maxPostSize) {
context.handleError(new Error('LARGE_UPLOAD'));
return;
}

var form = new formidable.IncomingForm();
form.uploadDir = uploadsDir;
form.parse(req, function(err, fields, files) {
for(var i in fields) {
context.params[i] = fields[i]
}
if(err) {
context.handleError(err);
} else {
for(var i in fields) {
context.params[i] = fields[i]
}

for(var i in files) {
context.params[i] = files[i];
for(var i in files) {
context.params[i] = files[i];
}
callback();
}
callback();
});
};

2 changes: 1 addition & 1 deletion lib/renderer.js
Expand Up @@ -187,7 +187,7 @@ RequestContext.prototype.renderError = function(status, error) {
fs.stat(viewFile, function(err, stats) {
if(!err && stats.isFile()) {
try {
var content = ghp.fill(viewFile, {error: error}, self.encoding, viewsDir, this.extn);
var content = ghp.fill(viewFile, {error: error}, self.encoding, viewsDir, self.extn);
self.send(content);
} catch(e) {
self.handleError(e);
Expand Down

0 comments on commit 7040a22

Please sign in to comment.