Skip to content

Commit

Permalink
Merge pull request hapijs#206 from wpreul/develop
Browse files Browse the repository at this point in the history
Fixing issue with error responses being cached + test
  • Loading branch information
Eran Hammer-Lahav committed Oct 31, 2012
2 parents e43b1f8 + f7d4573 commit e0e61f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ internals.Request.prototype._generateResponse = function () {

// Check for Error result

if (response instanceof Error) {
if (response.result instanceof Error) {
self.log(['handler', 'result', 'error'], { msec: timer.elapsed() });
return callback(response);
}
Expand Down
23 changes: 22 additions & 1 deletion test/integration/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,23 @@ describe('Cache', function() {
request.reply.stream(new Stream);
};

var errorHandler = function (request) {

var error = new Error('myerror');
error.code = 500;

request.reply(error);
};

function setupServer(done) {
_server = new Hapi.Server('0.0.0.0', 18085, { cache: 'memory' });
_server.addRoutes([
{ method: 'GET', path: '/profile', config: { handler: profileHandler, cache: { mode: 'client', expiresIn: 120000 } } },
{ method: 'GET', path: '/item', config: { handler: activeItemHandler, cache: { mode: 'client', expiresIn: 120000 } } },
{ method: 'GET', path: '/item2', config: { handler: activeItemHandler, cache: { mode: 'none' } } },
{ method: 'GET', path: '/item3', config: { handler: activeItemHandler, cache: { mode: 'client', expiresIn: 120000 } } },
{ method: 'GET', path: '/bad', config: { handler: badHandler, cache: { expiresIn: 120000 } } }
{ method: 'GET', path: '/bad', config: { handler: badHandler, cache: { expiresIn: 120000 } } },
{ method: 'GET', path: '/error', config: { handler: errorHandler, cache: { expiresIn: 120000 } } }
]);
_server.listener.on('listening', function() {
done();
Expand Down Expand Up @@ -104,4 +113,16 @@ describe('Cache', function() {
expect(test).to.throw(Error);
done();
});

it('doesn\'t cache error responses', function(done) {

makeRequest('/error', function() {

_server.cache.get({ segment: '/error', id: '/error' }, function(err, cached) {

expect(cached).to.not.exist;
done();
});
});
});
});

0 comments on commit e0e61f5

Please sign in to comment.