From 356ab0dd7435305c70fa9662b7e6e4a871df07ae Mon Sep 17 00:00:00 2001 From: Martii Date: Tue, 19 Aug 2014 13:51:52 -0600 Subject: [PATCH] Fix proper response codes based off of most probable statusCode Applies to #296 **NOTE** Prior code deduced from other routines which probably have the same issue. --- controllers/document.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/controllers/document.js b/controllers/document.js index 4f71f4855..33f113648 100644 --- a/controllers/document.js +++ b/controllers/document.js @@ -34,7 +34,10 @@ exports.view = function (aReq, aRes, aNext) { // Read file listing function (aCallback) { fs.readdir(documentPath, function (aErr, aFiles) { - if (aErr) { aCallback('Error retrieving page list'); return; } + if (aErr) { + aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' }); + return; + } var file = null; @@ -56,7 +59,10 @@ exports.view = function (aReq, aRes, aNext) { // Read md file contents function (aCallback) { fs.readFile(documentPath + '/' + document + '.md', 'UTF8', function (aErr, aData) { - if (aErr) { aCallback('Error retrieving page'); return; } + if (aErr) { + aCallback({ statusCode: 404, statusMessage: 'Error retrieving page' }); + return; + } var lines = null; var matches = null; @@ -101,7 +107,8 @@ exports.view = function (aReq, aRes, aNext) { async.parallel(tasks, function (aErr) { if (aErr) { return statusCodePage(aReq, aRes, aNext, { - statusMessage: aErr + statusCode: aErr.statusCode, + statusMessage: aErr.statusMessage }) }