Skip to content

Commit

Permalink
version 1.1.64
Browse files Browse the repository at this point in the history
  • Loading branch information
dgofman committed Dec 2, 2015
1 parent d22ad37 commit c290913
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
6 changes: 4 additions & 2 deletions indigo.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ var indigo =
debug('inject: %s -> %s', url, newUrl);
try {
req.model.filename = getModuleWebDir(req) + newUrl;
req.model.locale = app.locals.locale;
for (var name in indigo.app.locals) {
req.model[name] = indigo.app.locals[name];
}
return ejs.render(fs.readFileSync(req.model.filename, 'utf-8'), req.model);
} catch(err) {
return errorHandler.injectErrorHandler(err).message;
Expand Down Expand Up @@ -306,9 +308,9 @@ var indigo =
res.status(404);
res.setHeader && res.setHeader('path', fileName);
}

res.render(fileName, req.model, function(err, result) {
if (err) {
console.error(err);
indigo.error(err, req, res);
} else {
res.send(result);
Expand Down
16 changes: 9 additions & 7 deletions libs/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ var errorHandler = function(appconf) {

return errorHandler.render = function(err, req, res, next) {
if (err) {

var model = {
code: err.statusCode || res.statusCode
},
var model = req.model || {},
code = err.statusCode || res.statusCode,
template = appconf.get('errors:template'),
url = appconf.get('errors:' + model.code);
url = appconf.get('errors:' + code);

model.code = code;

if (model.code === 404) {
model.message = 'Not Found';
Expand All @@ -64,12 +64,14 @@ var errorHandler = function(appconf) {
model.details = 'Please contact your system administrator.';
}

errorHandler.error('ERROR2_' + model.code, err instanceof Error ? err : JSON.stringify(err), model.message, req.url);
if (!req.headers || req.headers['error_verbose'] !== 'false') {
errorHandler.error('ERROR2_' + model.code, err instanceof Error ? err : JSON.stringify(err), model.message, req.url);
}

if (url && url.length > 0){
res.redirect(url);
} else {
res.status(202).render(__appDir + (template || '/node_modules/indigojs/examples/templates/errors.html'), model);
res.status(model.code).render(__appDir + (template || '/node_modules/indigojs/examples/templates/errors.html'), model);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "indigojs",
"version": "1.1.63",
"version": "1.1.64",
"description": "IndigoJS is an open source, JavaScript/NodeJS localization framework",
"main": "indigo.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/mocha/firststep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Testing FirstStep example', function () {
indigo.close(done);
});

it('should test GET', function(done){
it('should test GET', function(done) {
superagent.get('http://localhost:' + port + '/firststep/index')
.end(function(err, res) {
assert.equal(res.statusCode, 200);
Expand All @@ -27,7 +27,7 @@ describe('Testing FirstStep example', function () {
});
});

it('should test GET', function(done){
it('should test GET', function(done) {
superagent.get('http://localhost:' + port + '/firststep/index')
.end(function(err, res) {
assert.equal(res.statusCode, 200);
Expand Down
11 changes: 11 additions & 0 deletions test/mocha/indigo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ describe('Testing Indigo API\'s', function () {
});
});

it('should test rendering error with error_verbose=false', function (done) {
indigo.start(__appDir + '/examples/firststep/config/app.json', null, function() {
var port = indigo.appconf.get('server:port');
superagent.get('http://localhost:' + port + '/firststep/invalidTemplate')
.set('error_verbose', false)
.end(function() {
indigo.close(done);
});
});
});

it('should test rendering error', function (done) {
indigo.start(__appDir + '/examples/firststep/config/app.json', null, function() {
var port = indigo.appconf.get('server:port');
Expand Down
1 change: 0 additions & 1 deletion test/unittest/indigo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ describe('UnitTests Indigo APIs', function () {
}
},res = {
render: function(url, model) {
console.log(fixPath(url), fixPath(__appDir) + '/examples/account/web/en/login.html');
assert.equal(fixPath(url), fixPath(__appDir) + '/examples/account/web/en/login.html');
assert.equal(model.locality.locale, 'en-gb');
assert.equal(model.locality.langugage, 'en');
Expand Down
8 changes: 4 additions & 4 deletions test/unittest/libs/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('libs/errorHandler', function () {
{
statusCode: 404,
status: function(code) {
assert.equal(code, 202);
assert.equal(code, 404);
return {
render: function(url, model) {
assert.equal(model.code, 404);
Expand All @@ -57,7 +57,7 @@ describe('libs/errorHandler', function () {
}, {
statusCode: 500,
status: function(code) {
assert.equal(code, 202);
assert.equal(code, 500);
return {
render: function(url, model) {
assert.equal(model.code, 500);
Expand All @@ -76,7 +76,7 @@ describe('libs/errorHandler', function () {
}, {
statusCode: 503,
status: function(code) {
assert.equal(code, 202);
assert.equal(code, 503);
return {
render: function(url, model) {
assert.equal(model.code, 503);
Expand All @@ -96,7 +96,7 @@ describe('libs/errorHandler', function () {
}, {
statusCode: 911,
status: function(code) {
assert.equal(code, 202);
assert.equal(code, 911);
return {
render: function(url, model) {
assert.equal(model.code, 911);
Expand Down

0 comments on commit c290913

Please sign in to comment.