diff --git a/api/server.js b/api/server.js index 2fe1a00128b..8b9835b8954 100644 --- a/api/server.js +++ b/api/server.js @@ -2,10 +2,16 @@ const db = require('./src/db-pouch'), serverChecks = require('@shared-libs/server-checks'), logger = require('./src/logger'); -process.on('unhandledRejection', reason => { - logger.error('Unhandled Rejection:'); - logger.error('%o',reason); -}); +process + .on('unhandledRejection', reason => { + logger.error('UNHANDLED REJECTION!'); + logger.error(' Reason: %o', reason); + }) + .on('uncaughtException', err => { + logger.error('UNCAUGHT EXCEPTION!'); + logger.error(' Error: %o', err); + process.exit(1); + }); serverChecks.check(db.serverUrl).then(() => { const app = require('./src/routing'), diff --git a/api/src/controllers/login.js b/api/src/controllers/login.js index 7f6f282a3bf..057f875e03b 100644 --- a/api/src/controllers/login.js +++ b/api/src/controllers/login.js @@ -165,7 +165,7 @@ const setCookies = (req, res, sessionRes) => { module.exports = { safePath: safePath, - get: (req, res) => { + get: (req, res, next) => { const redirect = safePath(req.query.redirect); return auth .getUserCtx(req) @@ -178,7 +178,7 @@ module.exports = { renderLogin(redirect, (err, body) => { if (err) { logger.error('Could not find login page'); - throw err; + return next(err); } res.send(body); }); diff --git a/api/src/routing.js b/api/src/routing.js index 4d38329cefc..7991e838bff 100644 --- a/api/src/routing.js +++ b/api/src/routing.js @@ -31,7 +31,6 @@ const _ = require('underscore'), bulkDocs = require('./controllers/bulk-docs'), authorization = require('./middleware/authorization'), createUserDb = require('./controllers/create-user-db'), - createDomain = require('domain').create, staticResources = /\/(templates|static)\//, favicon = /\/icon_\d+.ico$/, // CouchDB is very relaxed in matching routes @@ -121,18 +120,6 @@ app.use( }) ); -app.use(function(req, res, next) { - var domain = createDomain(); - domain.on('error', function(err) { - logger.error('UNCAUGHT EXCEPTION!'); - serverUtils.serverError(err, req, res); - domain.dispose(); - process.exit(1); - }); - domain.enter(); - next(); -}); - // requires `req` header `Accept-Encoding` to be `gzip` or `deflate` // requires `res` `Content-Type` to be compressible (see https://github.com/jshttp/mime-db/blob/master/db.json) // default threshold is 1KB