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

reliable-get

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reliable-get - npm Package Compare versions

Comparing version 0.1.26 to 0.1.28

14

index.js

@@ -11,2 +11,3 @@ 'use strict';

var CacheFactory = require('./lib/cache/cacheFactory');
var statusCodeToErrorLevelMap = {'3': 'info', '4': 'warn', '5': 'error' };

@@ -38,7 +39,10 @@ function ReliableGet(config) {

inErrorState = true;
var message = sf('Service {url} FAILED due to {errorMessage}', {
var message = sf('Service {url} responded with {errorMessage}', {
url: options.url,
errorMessage: err.message
});
self.emit('log', 'error', 'FAIL ' + message, {tracer:options.tracer, statusCode: statusCode, type:options.type});
var statusGroup = '' + Math.floor(statusCode / 100);
var errorLevel = statusCodeToErrorLevelMap[statusGroup] || 'error';
var errorMessage = (errorLevel === 'error' ? 'FAIL ' + message : message);
self.emit('log', errorLevel, errorMessage, {tracer:options.tracer, statusCode: statusCode, type:options.type});
self.emit('stat', 'increment', options.statsdKey + '.requestError');

@@ -116,4 +120,6 @@ cb({statusCode: statusCode || 500, message: message, headers: headers});

} else {
self.emit('log', 'warn', 'Error and no stale cache available for key: ' + options.cacheKey, {tracer: options.tracer, type: options.type});
self.emit('stat', 'increment', options.statsdKey + '.cacheNoStale');
if(cache.engine !== 'nocache') {
self.emit('log', 'warn', 'Error and no stale cache available for key: ' + options.cacheKey, {tracer: options.tracer, type: options.type});
self.emit('stat', 'increment', options.statsdKey + '.cacheNoStale');
}
}

@@ -120,0 +126,0 @@ return next(err, staleContent);

{
"name": "reliable-get",
"version": "0.1.26",
"version": "0.1.28",
"description": "A circuit breaker and cached wrapper for GET requests (enables reliable external service interaction).",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -98,2 +98,46 @@ 'use strict';

it('NO CACHE: should only log ERROR for 500', function(done) {
var config = {cache:{engine:'nocache'}, followRedirect: false};
var rg = new ReliableGet(config);
rg.on('log', function(level, message) {
if (level === 'error') {
expect(message).to.contain('FAIL');
done();
}
});
rg.get({url:'http://localhost:5001/faulty?faulty=true', timeout: 5}, function(err, response) {
expect(err.statusCode).to.be(500);
});
});
it('NO CACHE: should only log WARNING for 404', function(done) {
var config = {cache:{engine:'nocache'}, followRedirect: false};
var rg = new ReliableGet(config);
rg.on('log', function(level, message) {
if (level === 'warn') {
expect(message).to.contain('with status code 404');
done();
}
});
rg.get({url:'http://localhost:5001/404', timeout: 5}, function(err, response) {
expect(err.statusCode).to.be(404);
});
});
it('NO CACHE: should only log INFO for redirects', function(done) {
var config = {cache:{engine:'nocache'}, followRedirect: false};
var rg = new ReliableGet(config);
rg.on('log', function(level, message) {
if (level === 'info') {
expect(message).to.contain('with status code 302');
done();
}
});
rg.get({url:'http://localhost:5001/302', timeout: 5}, function(err, response) {
expect(err.statusCode).to.be(302);
expect(err.headers.location).to.be('/');
});
});
it('MEMORY CACHE: should initialise with caching on with simple defaults if none provided', function(done) {

@@ -100,0 +144,0 @@ var config = {cache:{engine:'memorycache'}};

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