flashheart
Advanced tools
Comparing version 2.8.1 to 2.8.3
@@ -76,3 +76,5 @@ var _ = require('lodash'); | ||
var key = createKeyObject(url, opts, doNotVary); | ||
return _.extend({}, key, { id: 'stale:' + key.id }); | ||
return _.extend({}, key, { | ||
id: 'stale:' + key.id | ||
}); | ||
} | ||
@@ -119,3 +121,3 @@ | ||
if (client.staleIfError && staleIfError) { | ||
if (!err && client.staleIfError && staleIfError) { | ||
cache.set(createStaleKeyObject(url, opts, doNotVary), cachedObject, staleIfError, client._handleCacheError.bind(client)); | ||
@@ -168,3 +170,3 @@ } | ||
if (err) client._handleCacheError(err); | ||
if (!cached) return cb(originalErr, body, res); | ||
if (!cached || cached.item.error) return cb(originalErr, body, res); | ||
if (delegate.stats) delegate.stats.increment(delegate.name + '.cache.stale'); | ||
@@ -171,0 +173,0 @@ |
{ | ||
"name": "flashheart", | ||
"version": "2.8.1", | ||
"version": "2.8.3", | ||
"description": "A fully-featured REST client built for ease-of-use and resilience", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -201,2 +201,19 @@ var async = require('async'); | ||
it('does not store a stale error', function (done) { | ||
var errorResponseCode = 404; | ||
var errorResponseBody = { | ||
error: 'An error' | ||
}; | ||
nock.cleanAll(); | ||
api.get('/').reply(errorResponseCode, errorResponseBody, headers); | ||
staleClient.get(url, function (err) { | ||
assert.ok(err); | ||
sinon.assert.calledOnce(catbox.set); | ||
sinon.assert.calledWith(catbox.set, expectedKey, sinon.match.object, 60000); | ||
done(); | ||
}); | ||
}); | ||
it('does not read stale cache if staleIfError is not enabled', function (done) { | ||
@@ -224,3 +241,3 @@ var errorResponseCode = 503; | ||
it('returns an error from the cache if it exists', function (done) { | ||
it('returns an error from the max-age cache if it exists', function (done) { | ||
var errorResponseBody = { | ||
@@ -255,2 +272,25 @@ error: 'An error' | ||
it('returns the non-cached error if the stale cache is an error', function (done) { | ||
var errorResponseCode = 503; | ||
var errorResponseBody = { | ||
error: 'An error' | ||
}; | ||
catbox.get.withArgs(expectedStaleKey).yields(null, { | ||
item: { | ||
error: 'Dieser Fehler wird nicht ausgegeben!', | ||
} | ||
}); | ||
nock.cleanAll(); | ||
api.get('/').reply(errorResponseCode, errorResponseBody, headers); | ||
staleClient.get(url, function (err) { | ||
assert.ok(err); | ||
sinon.assert.calledTwice(catbox.get); | ||
assert.deepEqual(err.body, errorResponseBody); | ||
done(); | ||
}); | ||
}); | ||
it('makes a request when the value stored in the cache doesn\'t contain the response body', function (done) { | ||
@@ -257,0 +297,0 @@ catbox.get.withArgs(expectedKey).yields(null, { |
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
282684
1841