diff --git a/lib/translator/index.js b/lib/translator/index.js index 823b0aa..8d6c8d2 100644 --- a/lib/translator/index.js +++ b/lib/translator/index.js @@ -105,7 +105,7 @@ Translator.prototype.translate = function (key, parameters) { try { return this._formatFunctions[key](parameters); } catch (err) { - this._logger.error(err); + this._logger.error(err.message); return ''; } }; diff --git a/spec/lib/translator.js b/spec/lib/translator.js index 0a065c0..aa7b8eb 100644 --- a/spec/lib/translator.js +++ b/spec/lib/translator.js @@ -131,6 +131,7 @@ describe('Translator', () => { expect(translator.translate('hello')).to.equal(''); expect(loggerStub.error.called).to.equal(true); + expect(loggerStub.error.getCall(0).args[0]).to.equal("MessageFormat: Data required for 'name'.") done(); }); @@ -143,8 +144,10 @@ describe('Translator', () => { }, loggerStub); const result = translator.translate('items_with_syntax_error', { count: 1 }); + const errMessage = 'Language File Syntax Error: Expected "plural" or "select" but "p" found. for key "items_with_syntax_error"'; expect(result).to.equal(""); expect(loggerStub.error.called).to.equal(true); + expect(loggerStub.error.getCall(0).args[0]).to.equal(errMessage); done(); });