Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-model

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-model - npm Package Compare versions

Comparing version 4.2.0 to 4.3.0

21

lib/remote-model.js

@@ -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 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc