From 72ec68f4c28bc644809f65e78158fe17ae38aecf Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 2 Dec 2016 17:48:07 +0100 Subject: [PATCH] additional backend error logging --- service/mget.js | 13 +++++++++++-- service/search.js | 15 ++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) 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 = [];