diff --git a/.gitignore b/.gitignore index e920c16..9987adc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ node_modules # Optional REPL history .node_repl_history + +# globalization +intl/* +!intl/en/ diff --git a/intl/en/messages.json b/intl/en/messages.json new file mode 100644 index 0000000..474b125 --- /dev/null +++ b/intl/en/messages.json @@ -0,0 +1,4 @@ +{ + "85312d2b987e2e44001db3d6963a1364": "Unhandled array of errors for request {0} {1}\n", + "adcbd4c562b19f45fb5d3427619646d5": "Unhandled error for request {0} {1}: {2}" +} diff --git a/lib/handler.js b/lib/handler.js index fb6196d..26eadf6 100644 --- a/lib/handler.js +++ b/lib/handler.js @@ -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; diff --git a/lib/logger.js b/lib/logger.js index 1cbc0ba..44a5d64 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -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) { diff --git a/package.json b/package.json index fcc49f8..6bb73a7 100644 --- a/package.json +++ b/package.json @@ -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",