Skip to content

Commit

Permalink
server: tell user if no file received
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Jan 15, 2011
1 parent d4d40db commit 7c2fba5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server.js
Expand Up @@ -27,7 +27,7 @@ function app(app) {
filename: part.filename,
mime: part.mime
} });
var out = files.addFile({ name: part.filename,
out = files.addFile({ name: part.filename,
type: part.mime
});
var received = 0;
Expand Down Expand Up @@ -56,14 +56,19 @@ function app(app) {
form.parse(req, function(err, fields, files) { if (!error) error = err; });

req.on('end', function() {
if (!out && !error)
error = new Error('No file received');

if (error) {
/* Error */
console.error(error.stack);
res.writeHead(400, HTML_HEADERS);
res.write(template.htmlHead);
res.write(template.error(error || new Error('No file received')));
res.write(template.htmlFoot);
res.end();
} else {
/* Success */
res.writeHead(200, HTML_HEADERS);
res.write(template.htmlHead);
res.write(template.thanks);
Expand Down

0 comments on commit 7c2fba5

Please sign in to comment.