From 3d66d3b48033b2bb211496cd1649312a253e0e65 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Mon, 19 Oct 2015 17:01:19 -0400 Subject: [PATCH] Added ability to override error handles for HTML controllers. --- include/http/request_handler.js | 14 +++--- include/system/system.js | 2 +- .../formatters/error_formatters_tests.js | 48 ++++++++++++------- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index cee4516c8..8da39f588 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -637,24 +637,24 @@ module.exports = function RequestHandlerModule(pb) { return cb(null, self.activeTheme); } - var settingsService = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.siteObj.uid); + var settingsService = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.siteObj.uid); settingsService.get('active_theme', function(err, activeTheme){ self.activeTheme = activeTheme; cb(null, activeTheme); }); }; - getActiveTheme(function(err, activeTheme) { + getActiveTheme(function(error, activeTheme) { //build out params for handlers var params = { - mime: this.themeRoute && this.themeRoute.content_type ? this.themeRoute.content_type : 'text/html', + mime: self.themeRoute && self.themeRoute.content_type ? self.themeRoute.content_type : 'text/html', error: err, - request: this.req, - localization: this.localization, + request: self.req, + localization: self.localization, activeTheme: activeTheme, - reqHandler: this, - errorCount: this.errorCount + reqHandler: self, + errorCount: self.errorCount }; //hand off to the formatters. NOTE: the callback may not be called if diff --git a/include/system/system.js b/include/system/system.js index bd4962ad1..b036e9437 100755 --- a/include/system/system.js +++ b/include/system/system.js @@ -296,7 +296,7 @@ module.exports = function System(pb){ }); process.on ('uncaughtException', function(err) { - log.debug('System[%s]: uncaughtException detected %s: ', self.getWorkerId(), IS_SHUTTING_DOWN ? 'but is already shutting down' : '', err.stack); + log.error('System[%s]: uncaught Exception detected %s: ', self.getWorkerId(), IS_SHUTTING_DOWN ? 'but is already shutting down' : '', err.stack); if (!IS_SHUTTING_DOWN) { self.shutdown(killProcess); } diff --git a/test/include/error/formatters/error_formatters_tests.js b/test/include/error/formatters/error_formatters_tests.js index aea3c5b81..ce4918244 100644 --- a/test/include/error/formatters/error_formatters_tests.js +++ b/test/include/error/formatters/error_formatters_tests.js @@ -76,15 +76,23 @@ describe('ErrorFormatters', function() { describe('ErrorFormatters.html', function() { - it('should return a string that represents HTML', function(next) { + it('should call the request handler to execute a controller', function() { + var resultContext = null; + var error = new Error('hello world'); + error.code = 510; + var params = { - error: new Error('hello world') + error: error, + activeTheme: 'pencilblue', + reqHandler: { + doRender: function(context) { + resultContext = context; + } + } }; - ErrorFormatters.html(params, function(err, result){ - - result.should.be.type('string'); - next(err); - }); + ErrorFormatters.html(params, function(err, result){}); + resultContext.initParams.error.should.eql(error); + resultContext.cInstance.should.not.be.null; }); }); @@ -156,20 +164,26 @@ describe('ErrorFormatters', function() { }); }); - it('should return a string that represents HTML when provided an unknown formatter', function(next) { + it('should return a string that represents HTML when provided an unknown formatter', function() { + var resultContext = null; + var error = new Error('hello world'); + error.code = 503; var params = { mime: 'application/non-existing', - error: new Error('hello world') + error: error, + activeTheme: 'pencilblue', + reqHandler: { + doRender: function(context) { + resultContext = context; + } + } }; - ErrorFormatters.formatForMime(params, function(err, result){ + ErrorFormatters.formatForMime(params, function(err, result){}); + resultContext.initParams.error.should.eql(error); + resultContext.cInstance.should.not.be.null; - var formatter = ErrorFormatters.get(params.mime); - should.strictEqual(formatter, undefined); - result.should.be.type('object'); - result.content.should.be.type('string'); - result.mime.should.eql('text/html'); - next(err); - }); + var formatter = ErrorFormatters.get(params.mime); + should.strictEqual(formatter, undefined); }); it('should throw when an error is not provided', function(next) {