diff --git a/service/mget.js b/service/mget.js index d021efd1..c709f28e 100644 --- a/service/mget.js +++ b/service/mget.js @@ -11,7 +11,7 @@ **/ -var peliasLogger = require( 'pelias-logger' ).get( 'api' ); +var logger = require( 'pelias-logger' ).get( 'api' ); function service( backend, query, cb ){ @@ -24,8 +24,17 @@ function service( backend, query, cb ){ // query new backend backend().client.mget( cmd, function( err, data ){ + + // log total ms elasticsearch reported the query took to execute + if( data && data.took ){ + logger.verbose( 'time elasticsearch reported:', data.took / 1000 ); + } + // handle backend errors - if( err ){ return cb( err ); } + if( err ){ + logger.error( 'backend error', err ); + return cb( err ); + } // map returned documents var docs = []; diff --git a/service/search.js b/service/search.js index 2d9c9adf..8e12b69e 100644 --- a/service/search.js +++ b/service/search.js @@ -5,18 +5,23 @@ **/ -var peliasLogger = require( 'pelias-logger' ).get( 'api' ); +var logger = require( 'pelias-logger' ).get( 'api' ); function service( backend, cmd, cb ){ // query new backend backend().client.search( cmd, function( err, data ){ - // handle backend errors - if( err ){ return cb( err ); } - // log total ms elasticsearch reported the query took to execute - peliasLogger.verbose( 'time elasticsearch reported:', data.took / 1000 ); + if( data && data.took ){ + logger.verbose( 'time elasticsearch reported:', data.took / 1000 ); + } + + // handle backend errors + if( err ){ + logger.error( 'backend error', err ); + return cb( err ); + } // map returned documents var docs = [];