Browse Source

added helper functions

pull/782/head
Stephen Hess 8 years ago
parent
commit
5148198e1d
  1. 12
      controller/search.js

12
controller/search.js

@ -8,6 +8,14 @@ const logging = require( '../helper/logging' );
const retry = require('retry'); const retry = require('retry');
function setup( apiConfig, esclient, query ){ function setup( apiConfig, esclient, query ){
function requestHasErrors(request) {
return _.get(request, 'errors', []).length > 0;
}
function responseHasData(response) {
return _.get(response, 'data', []).length > 0;
}
function isRequestTimeout(err) { function isRequestTimeout(err) {
return _.get(err, 'status') === 408; return _.get(err, 'status') === 408;
} }
@ -15,14 +23,14 @@ function setup( apiConfig, esclient, query ){
function controller( req, res, next ){ function controller( req, res, next ){
// do not run controller when a request // do not run controller when a request
// validation error has occurred. // validation error has occurred.
if (_.get(req, 'errors', []).length > 0) { if (requestHasErrors(req)) {
return next(); return next();
} }
// do not run controller if there are already results // do not run controller if there are already results
// this was added during libpostal integration. if the libpostal parse/query // this was added during libpostal integration. if the libpostal parse/query
// doesn't return anything then fallback to old search-engine-y behavior // doesn't return anything then fallback to old search-engine-y behavior
if (_.get(res, 'data', []).length > 0) { if (responseHasData(res)) {
return next(); return next();
} }

Loading…
Cancel
Save