From daee86852327e02cf7fde12f8a65e5af02bb3b93 Mon Sep 17 00:00:00 2001 From: Dave Tapley Date: Tue, 8 Apr 2014 11:11:06 -0700 Subject: [PATCH] Respond with 500 when an error occurs, instead of trying to use next which isn't part of the http.createServer callback --- Example.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Example.md b/Example.md index f538e2d..d40707c 100644 --- a/Example.md +++ b/Example.md @@ -8,7 +8,7 @@ var pg = require('pg'); var conString = "postgres://postgres:1234@localhost/postgres"; -var server = http.createServer(function(req, res, next) { +var server = http.createServer(function(req, res) { // get a pg client from the connection pool pg.connect(conString, function(err, client, done) { @@ -23,7 +23,8 @@ var server = http.createServer(function(req, res, next) { // In this case, if we have successfully, received a client (truthy) // then it will be removed from the pool. done(client); - next(err); + res.writeHead(500, {'content-type': 'text/html'}); + res.end('An error occurred'); return true; };