hmpo-model
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -12,2 +12,4 @@ 'use strict'; | ||
const consoleLogger = { outbound: console.log, trimHtml: html => html }; | ||
class RemoteModel extends LocalModel { | ||
@@ -23,10 +25,13 @@ constructor(attributes, options) { | ||
try { | ||
const hmpoLogger = require('hmpo-logger'); | ||
this.logger = hmpoLogger.get(':' + this.options.label); | ||
this.logger = require('hmpo-logger'); | ||
} catch (e) { | ||
console.error('Error setting logger, using console instead!', e); | ||
this.logger = { outbound: console.log, trimHtml: html => html }; | ||
/* istanbul ignore next */ | ||
console.warn('Warning: ' + this.options.label + ': Unable to find hmpo-logger for logging, using console instead!'); | ||
} | ||
} | ||
getLogger() { | ||
return this.logger ? this.logger.get(':' + this.options.label) : consoleLogger; | ||
} | ||
fetch(args, callback) { | ||
@@ -269,3 +274,3 @@ if (typeof args === 'function') { | ||
if (tokenData.err) { | ||
data.outErrorBody = this.logger.trimHtml(tokenData.err.body); | ||
data.outErrorBody = this.getLogger().trimHtml(tokenData.err.body); | ||
} | ||
@@ -280,11 +285,11 @@ | ||
logSync() { | ||
this.logger.outbound('Model request sent :outVerb :outRequest', this.logMeta.apply(this, arguments)); | ||
this.getLogger().outbound('Model request sent :outVerb :outRequest', this.logMeta.apply(this, arguments)); | ||
} | ||
logSuccess() { | ||
this.logger.outbound('Model request success :outVerb :outRequest :outResponseCode', this.logMeta.apply(this, arguments)); | ||
this.getLogger().outbound('Model request success :outVerb :outRequest :outResponseCode', this.logMeta.apply(this, arguments)); | ||
} | ||
logError() { | ||
this.logger.outbound('Model request failed :outVerb :outRequest :outResponseCode :outError', this.logMeta.apply(this, arguments)); | ||
this.getLogger().outbound('Model request failed :outVerb :outRequest :outResponseCode :outError', this.logMeta.apply(this, arguments)); | ||
} | ||
@@ -291,0 +296,0 @@ |
{ | ||
"name": "hmpo-model", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Simple model for interacting with http/rest apis.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -70,15 +70,14 @@ 'use strict'; | ||
model.getLogger().should.equal('logger'); | ||
logger.get.should.have.been.calledWithExactly(':remote-model'); | ||
model.logger.should.equal('logger'); | ||
}); | ||
it('should use console log and a trimHtml pass-through if hmpo-logger is not available', () => { | ||
logger.get.throws({ message: 'test error' }); | ||
model = new Model(); | ||
model.logger = null; | ||
model.logger.outbound.should.eql(console.log); | ||
model.logger.trimHtml.should.be.a('function'); | ||
model.getLogger().outbound.should.eql(console.log); | ||
model.getLogger().trimHtml.should.be.a('function'); | ||
const html = {}; | ||
model.logger.trimHtml(html).should.equal(html); | ||
model.getLogger().trimHtml(html).should.equal(html); | ||
}); | ||
@@ -85,0 +84,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72258
1655