From a6ce7008317d06e032339db3b0dc5254115a10d4 Mon Sep 17 00:00:00 2001 From: Julie Myers Date: Tue, 24 Mar 2015 04:26:39 -0600 Subject: [PATCH 1/3] Add chai-jquery to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 732eb867872..dadcd039611 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "async": "^0.9.0", "bcrypt-nodejs": "^0.0.3", "body-parser": "^1.9.3", + "chai-jquery": "^2.0.0", "cheerio": "^0.18.0", "clockwork": "^0.1.1", "compression": "^1.2.1", From 2b0cc9175496ff90b94ef2dfd5e082720efce344 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 24 Mar 2015 08:03:59 -0700 Subject: [PATCH 2/3] Add production error handler --- app.js | 44 +++++++++++++++++++++++++++++++++++++++++--- package.json | 1 + 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 55850d9ab7b..ecbdc18fd5b 100644 --- a/app.js +++ b/app.js @@ -15,6 +15,7 @@ process.on('uncaughtException', function (err) { }); var express = require('express'), + accepts = require('accepts'), cookieParser = require('cookie-parser'), compress = require('compression'), session = require('express-session'), @@ -524,17 +525,54 @@ app.get( } ); -//put this route last +app.get('/induce-vomiting', function(req, res, next) { + next(new Error('vomiting induced')); +}); + +// put this route last app.get( '/:username', userController.returnUser ); - /** * 500 Error Handler. */ -app.use(errorHandler()); +if (process.env.NODE_ENV === 'development') { + app.use(errorHandler({ log: true })); +} else { + // error handling in production + app.use(function(err, req, res, next) { + + // respect err.status + if (err.status) { + res.statusCode = err.status; + } + + // default status code to 500 + if (res.statusCode < 400) { + res.statusCode = 500; + } + + // parse res type + var accept = accepts(req); + var type = accept.type('html', 'json', 'text'); + + var message = 'opps! Something went wrong. Please try again later'; + if (type === 'html') { + req.flash('errors', { msg: message }); + return res.redirect('/'); + // json + } else if (type === 'json') { + res.setHeader('Content-Type', 'application/json'); + return res.send({ message: message }); + // plain text + } else { + res.setHeader('Content-Type', 'text/plain'); + return res.send(message); + } + }); +} /** * Start Express server. diff --git a/package.json b/package.json index dadcd039611..ffe8c6281b9 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "postinstall": "node seed_data/seed.js" }, "dependencies": { + "accepts": "^1.2.5", "async": "^0.9.0", "bcrypt-nodejs": "^0.0.3", "body-parser": "^1.9.3", From 482cc3fa7b477800353448f4f54c9edcd3ee0027 Mon Sep 17 00:00:00 2001 From: Geoff Storbeck Date: Tue, 24 Mar 2015 15:58:17 -0400 Subject: [PATCH 3/3] fixed typo for issue #266 --- seed_data/bonfires.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seed_data/bonfires.json b/seed_data/bonfires.json index c298c97db78..a686f7e7f75 100644 --- a/seed_data/bonfires.json +++ b/seed_data/bonfires.json @@ -176,7 +176,7 @@ "tests": [ "assert.deepEqual(chunk(['a', 'b', 'c', 'd'], 2), [['a', 'b'], ['c', 'd']], 'should return chunked arrays');", "assert.deepEqual(chunk([0, 1, 2, 3, 4, 5], 3), [[0, 1, 2], [3, 4, 5]], 'should return chunked arrays');", - "assert.deepEqual(chunk([0, 1, 2, 3, 4, 5], 4), [[0, 1, 2, 3], [4, 5]], 'should return cthe last chunk as remaining elements');" + "assert.deepEqual(chunk([0, 1, 2, 3, 4, 5], 4), [[0, 1, 2, 3], [4, 5]], 'should return the last chunk as remaining elements');" ] }, {