From 3acc2eb17dddbbdf2451c80847e3e835d528d27e Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Fri, 18 Nov 2011 16:28:09 -0500 Subject: [PATCH] Catch an error --- lib/document_handler.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/document_handler.js b/lib/document_handler.js index 84771d1..2be8805 100644 --- a/lib/document_handler.js +++ b/lib/document_handler.js @@ -26,6 +26,7 @@ DocumentHandler.prototype.handlePost = function(request, response) { var key = '123'; request.on('data', function(data) { if (!DocumentHandler.documents[key]) { + response.writeHead(200, { 'content-type': 'application/json' }); DocumentHandler.documents[key] = ''; } DocumentHandler.documents[key] += data.toString(); @@ -35,7 +36,9 @@ DocumentHandler.prototype.handlePost = function(request, response) { response.end(JSON.stringify({ key: key })); }); request.on('error', function(error) { - // TODO handle error + winston.error('connection error: ' + error.message); + response.writeHead(500, { 'content-type': 'application/json' }); + response.end(JSON.stringify({ message: 'connection error' })); }); };