Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

Commit

Permalink
pass all errors through so they get shown to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzoller committed Dec 1, 2011
1 parent d754527 commit 9364ace
Showing 1 changed file with 49 additions and 52 deletions.
101 changes: 49 additions & 52 deletions server/web.js
Expand Up @@ -34,62 +34,59 @@ app.post('/make', function(request, response, next) {
// form handler // form handler
request.form.complete(function(err, fields, files) { request.form.complete(function(err, fields, files) {


// if there's an error // if there's an error, pass through to the next handler
if (err) { if (err) { return next(err); }

// pass through to the next handler
next(err);


// match on the shared secret
if (fields.secret != process.env.SECRET) {
response.write('invalid secret');
response.send(500);
} else { } else {


// match on the shared secret var id = uuid();
if (fields.secret != process.env.SECRET) { var command = fields.command;
response.write('invalid secret'); var prefix = fields.prefix;
response.send(500);
} else { // create a couchdb documents for this build

db.save(id, { command:command, prefix:prefix }, function(err, doc) {
var id = uuid(); if (err) { return next(err); }
var command = fields.command;
var prefix = fields.prefix; // save the input tarball as an attachment

db.saveAttachment(
// create a couchdb documents for this build doc.id,
var doc = db.save(id, { command:command, prefix:prefix }, function(err, doc) { doc.rev,

'input',
// save the input tarball as an attachment 'application/octet-stream',
db.saveAttachment( fs.createReadStream(files.code.path),
doc.id, function(err, data) {
doc.rev, if (err) { return next(err); }
'input',
'application/octet-stream', // spawn bin/make with this build id
fs.createReadStream(files.code.path), var ls = spawner.spawn('bin/make ' + id, function(err) {
function(err, data) { response.write('could not spawn: ' + err);

response.send(500);
// spawn bin/make with this build id });
var ls = spawner.spawn('bin/make ' + id, function(err) {
response.write('could not spawn: ' + err); ls.on('error', function(error) {
response.send(500); response.write('error: ' + err);
}); response.send(500);

});
ls.on('error', function(error) {
response.write('error: ' + err); ls.on('data', function(data) {
response.send(500); response.write(data);
}); });


ls.on('data', function(data) { ls.on('exit', function(code) {
response.write(data); response.end();
}); });

}
ls.on('exit', function(code) { );
response.end();
}); // return the build id as a header
} response.header('X-Make-Id', id);
); });

// return the build id as a header
response.header('X-Make-Id', id);
});
}
} }

}); });
} }
}); });
Expand Down

0 comments on commit 9364ace

Please sign in to comment.