From e34b013f90300ee47351d1e5a844d6d2f822e988 Mon Sep 17 00:00:00 2001 From: Thalyta Fabrine Date: Sun, 11 Apr 2021 10:53:30 -0300 Subject: [PATCH] Add search-api error log --- CHANGELOG.md | 4 ++++ node/clients/biggy-search.ts | 40 +++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10291ca3..17c84b8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- Log for search-api errors. + ## [1.59.7] - 2021-12-28 ### Fixed diff --git a/node/clients/biggy-search.ts b/node/clients/biggy-search.ts index df5afd54..8bd53fa4 100644 --- a/node/clients/biggy-search.ts +++ b/node/clients/biggy-search.ts @@ -319,25 +319,33 @@ export class BiggySearchClient extends JanusClient { }) } - const result = await this.http.getRaw(url, { - params, - metric: 'search-result', - headers: { - "X-VTEX-IS-Filter": buildBSearchFilterHeader(sellers), - "X-VTEX-IS-ID": `${this.store}`, - }, - ...cache - }) - - if (!result.data?.total) { - this.context.logger.warn({ - message: 'Empty search', - url, + try { + const result = await this.http.getRaw(url, { params, + metric: 'search-result', + headers: { + "X-VTEX-IS-Filter": buildBSearchFilterHeader(sellers), + "X-VTEX-IS-ID": `${this.store}`, + }, + ...cache }) - } - return sortProducts(result.data, query) + if (!result.data?.total) { + this.context.logger.warn({ + message: 'Empty search', + url, + params, + }) + } + + return sortProducts(result.data, query) + } catch (error) { + this.context.logger.error({ + message: 'Error from search-api', + error, + }) + throw error + } } public async banners(args: BannersArgs): Promise {