fix error handling

This commit is contained in:
AJ ONeal 2015-03-02 22:42:14 +00:00
parent db7e736659
commit 0ae9e5a069
1 changed files with 35 additions and 35 deletions

View File

@ -28,9 +28,8 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
return dummyCerts;
}
function handleAppScopedError(fn) {
return function (req, res, next) {
next(function (err) {
function handleAppScopedError(req, res, fn) {
function next(err) {
if (!err) {
fn(req, res);
return;
@ -61,8 +60,9 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
+ "</body>"
+ "</html>"
);
});
}
return next;
}
function createSecureContext(certs) {
@ -135,14 +135,14 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
// we always add it explicitly
function localAppWrapped(req, res) {
console.log('[debug]', domaininfo.hostname + '/' + domaininfo.pathname, req.url);
localApp(req, res, handleAppScopedError(function () {
localApp(req, res, handleAppScopedError(req, res, function (req, res) {
if (!serveFavicon) {
serveFavicon = require('serve-favicon')(path.join(__dirname, '..', 'public', 'favicon.ico'));
}
// TODO redirect GET /favicon.ico to GET (req.headers.referer||'') + /favicon.ico
// TODO other common root things - robots.txt, app-icon, etc
serveFavicon(req, res, handleAppScopedError(function () {
serveFavicon(req, res, handleAppScopedError(req, res, function (req, res) {
res.writeHead(404);
res.end(
"<html>"