Merge pull request #20 from strongloop/globalize

Globalize strong-error-handler
This commit is contained in:
David Cheung 2016-08-17 20:05:38 -04:00 committed by GitHub
commit ad4e5728d4
5 changed files with 18 additions and 4 deletions

4
.gitignore vendored
View File

@ -31,3 +31,7 @@ node_modules
# Optional REPL history
.node_repl_history
# globalization
intl/*
!intl/en/

4
intl/en/messages.json Normal file
View File

@ -0,0 +1,4 @@
{
"85312d2b987e2e44001db3d6963a1364": "Unhandled array of errors for request {0} {1}\n",
"adcbd4c562b19f45fb5d3427619646d5": "Unhandled error for request {0} {1}: {2}"
}

View File

@ -5,6 +5,9 @@
'use strict';
var path = require('path');
var SG = require('strong-globalize');
SG.SetRootDir(path.resolve(__dirname, '..'));
var buildResponseData = require('./data-builder');
var debug = require('debug')('strong-error-handler');
var format = require('util').format;

View File

@ -6,17 +6,19 @@
'use strict';
var format = require('util').format;
var g = require('strong-globalize')();
module.exports = function logToConsole(req, err) {
if (!Array.isArray(err)) {
console.error('Unhandled error for request %s %s: %s',
g.error('Unhandled error for request %s %s: %s',
req.method, req.url, err.stack || err);
return;
}
var errMsg = g.f('Unhandled array of errors for request %s %s\n',
req.method, req.url);
var errors = err.map(formatError).join('\n');
console.error('Unhandled array of errors for request %s %s\n',
req.method, req.url, errors);
console.error(errMsg, errors);
};
function formatError(err) {

View File

@ -17,7 +17,8 @@
"accepts": "^1.3.3",
"debug": "^2.2.0",
"ejs": "^2.4.2",
"http-status": "^0.2.2"
"http-status": "^0.2.2",
"strong-globalize": "^2.6.7"
},
"devDependencies": {
"chai": "^2.1.1",