From b8b8522b3357f4fdad022736c58cdc37328560ab Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 19 Sep 2024 12:49:33 -0400 Subject: [PATCH] Nick: fixed map exception --- apps/api/src/search/fireEngine.ts | 67 ++++++++++++++++++------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/apps/api/src/search/fireEngine.ts b/apps/api/src/search/fireEngine.ts index 7c6d8a4d..d5e15656 100644 --- a/apps/api/src/search/fireEngine.ts +++ b/apps/api/src/search/fireEngine.ts @@ -1,10 +1,14 @@ import axios from "axios"; import dotenv from "dotenv"; import { SearchResult } from "../../src/lib/entities"; +import * as Sentry from "@sentry/node"; +import { Logger } from "../lib/logger"; dotenv.config(); -export async function fireEngineMap(q: string, options: { +export async function fireEngineMap( + q: string, + options: { tbs?: string; filter?: string; lang?: string; @@ -12,34 +16,43 @@ export async function fireEngineMap(q: string, options: { location?: string; numResults: number; page?: number; -}): Promise { - let data = JSON.stringify({ - query: q, - lang: options.lang, - country: options.country, - location: options.location, - tbs: options.tbs, - numResults: options.numResults, - page: options.page ?? 1, - }); - - if (!process.env.FIRE_ENGINE_BETA_URL) { - console.warn("(v1/map Beta) Results might differ from cloud offering currently."); - return []; } +): Promise { + try { + let data = JSON.stringify({ + query: q, + lang: options.lang, + country: options.country, + location: options.location, + tbs: options.tbs, + numResults: options.numResults, + page: options.page ?? 1, + }); - let config = { - method: "POST", - url: `${process.env.FIRE_ENGINE_BETA_URL}/search`, - headers: { - "Content-Type": "application/json", - }, - data: data, - }; - const response = await axios(config); - if (response && response) { - return response.data - } else { + if (!process.env.FIRE_ENGINE_BETA_URL) { + console.warn( + "(v1/map Beta) Results might differ from cloud offering currently." + ); + return []; + } + + let config = { + method: "POST", + url: `${process.env.FIRE_ENGINE_BETA_URL}/search`, + headers: { + "Content-Type": "application/json", + }, + data: data, + }; + const response = await axios(config); + if (response && response) { + return response.data; + } else { + return []; + } + } catch (error) { + Logger.error(error); + Sentry.captureException(error); return []; } }