Browse Source

Merge pull request #503 from pelias/fix_timeout_error

Fix timeout error handling
pull/508/head
Julian Simioni 9 years ago
parent
commit
bc39ddd970
  1. 6
      controller/search.js
  2. 15
      test/unit/controller/search.js
  3. 8
      test/unit/mock/backend.js

6
controller/search.js

@ -1,3 +1,5 @@
var _ = require('lodash');
var service = { search: require('../service/search') };
var logger = require('pelias-logger').get('api:controller:search');
@ -36,8 +38,12 @@ function setup( backend, query ){
// error handler
if( err ){
if (_.isObject(err) && err.message) {
req.errors.push( err.message );
} else {
req.errors.push( err );
}
}
// set response data
else {
res.data = docs;

15
test/unit/controller/search.js

@ -123,6 +123,21 @@ module.exports.tests.functional_failure = function(test, common) {
});
};
module.exports.tests.timeout = function(test, common) {
test('timeout', function(t) {
var backend = mockBackend( 'client/search/timeout/1', function( cmd ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command');
});
var controller = setup( backend, mockQuery() );
var req = { clean: { a: 'b' }, errors: [], warnings: [] };
var next = function(){
t.equal(req.errors[0],'Request Timeout after 5000ms');
t.end();
};
controller(req, undefined, next );
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {

8
test/unit/mock/backend.js

@ -33,6 +33,14 @@ responses['client/search/fail/1'] = function( cmd, cb ){
return cb( 'a backend error occurred' );
};
responses['client/search/timeout/1'] = function( cmd, cb) {
// timeout errors are objects
return cb({
status: 408,
message: 'Request Timeout after 5000ms'
});
};
responses['client/mget/ok/1'] = function( cmd, cb ){
return cb( undefined, mgetEnvelope([{
_id: 'myid1',

Loading…
Cancel
Save