Skip to content

Commit

Permalink
Added ability to override error handles for HTML controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Oct 19, 2015
1 parent d9a7af9 commit 3d66d3b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
14 changes: 7 additions & 7 deletions include/http/request_handler.js
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/system/system.js
Expand Up @@ -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);
}
Expand Down
48 changes: 31 additions & 17 deletions test/include/error/formatters/error_formatters_tests.js
Expand Up @@ -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;
});
});

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3d66d3b

Please sign in to comment.