Permalink
Browse files

pass all errors through so they get shown to the user

  • Loading branch information...
1 parent d754527 commit 9364ace4fa2167aef50b15f7378789c6726c0774 @bobzoller bobzoller committed Dec 1, 2011
Showing with 49 additions and 52 deletions.
  1. +49 −52 server/web.js
View
101 server/web.js
@@ -34,62 +34,59 @@ app.post('/make', function(request, response, next) {
// form handler
request.form.complete(function(err, fields, files) {
- // if there's an error
- if (err) {
-
- // pass through to the next handler
- next(err);
+ // if there's an error, pass through to the next handler
+ if (err) { return next(err); }
+ // match on the shared secret
+ if (fields.secret != process.env.SECRET) {
+ response.write('invalid secret');
+ response.send(500);
} else {
- // match on the shared secret
- if (fields.secret != process.env.SECRET) {
- response.write('invalid secret');
- response.send(500);
- } else {
-
- var id = uuid();
- var command = fields.command;
- var prefix = fields.prefix;
-
- // create a couchdb documents for this build
- var doc = db.save(id, { command:command, prefix:prefix }, function(err, doc) {
-
- // save the input tarball as an attachment
- db.saveAttachment(
- doc.id,
- doc.rev,
- 'input',
- 'application/octet-stream',
- fs.createReadStream(files.code.path),
- function(err, data) {
-
- // spawn bin/make with this build id
- var ls = spawner.spawn('bin/make ' + id, function(err) {
- response.write('could not spawn: ' + err);
- response.send(500);
- });
-
- ls.on('error', function(error) {
- response.write('error: ' + err);
- response.send(500);
- });
-
- ls.on('data', function(data) {
- response.write(data);
- });
-
- ls.on('exit', function(code) {
- response.end();
- });
- }
- );
-
- // return the build id as a header
- response.header('X-Make-Id', id);
- });
- }
+ var id = uuid();
+ var command = fields.command;
+ var prefix = fields.prefix;
+
+ // create a couchdb documents for this build
+ db.save(id, { command:command, prefix:prefix }, function(err, doc) {
+ if (err) { return next(err); }
+
+ // save the input tarball as an attachment
+ db.saveAttachment(
+ doc.id,
+ doc.rev,
+ 'input',
+ 'application/octet-stream',
+ fs.createReadStream(files.code.path),
+ function(err, data) {
+ if (err) { return next(err); }
+
+ // spawn bin/make with this build id
+ var ls = spawner.spawn('bin/make ' + id, function(err) {
+ response.write('could not spawn: ' + err);
+ response.send(500);
+ });
+
+ ls.on('error', function(error) {
+ response.write('error: ' + err);
+ response.send(500);
+ });
+
+ ls.on('data', function(data) {
+ response.write(data);
+ });
+
+ ls.on('exit', function(code) {
+ response.end();
+ });
+ }
+ );
+
+ // return the build id as a header
+ response.header('X-Make-Id', id);
+ });
}
+
});
}
});

0 comments on commit 9364ace

Please sign in to comment.