Nick: fixed map exception
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
import { SearchResult } from "../../src/lib/entities";
|
import { SearchResult } from "../../src/lib/entities";
|
||||||
|
import * as Sentry from "@sentry/node";
|
||||||
|
import { Logger } from "../lib/logger";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
export async function fireEngineMap(q: string, options: {
|
export async function fireEngineMap(
|
||||||
|
q: string,
|
||||||
|
options: {
|
||||||
tbs?: string;
|
tbs?: string;
|
||||||
filter?: string;
|
filter?: string;
|
||||||
lang?: string;
|
lang?: string;
|
||||||
@@ -12,34 +16,43 @@ export async function fireEngineMap(q: string, options: {
|
|||||||
location?: string;
|
location?: string;
|
||||||
numResults: number;
|
numResults: number;
|
||||||
page?: number;
|
page?: number;
|
||||||
}): Promise<SearchResult[]> {
|
|
||||||
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<SearchResult[]> {
|
||||||
|
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 = {
|
if (!process.env.FIRE_ENGINE_BETA_URL) {
|
||||||
method: "POST",
|
console.warn(
|
||||||
url: `${process.env.FIRE_ENGINE_BETA_URL}/search`,
|
"(v1/map Beta) Results might differ from cloud offering currently."
|
||||||
headers: {
|
);
|
||||||
"Content-Type": "application/json",
|
return [];
|
||||||
},
|
}
|
||||||
data: data,
|
|
||||||
};
|
let config = {
|
||||||
const response = await axios(config);
|
method: "POST",
|
||||||
if (response && response) {
|
url: `${process.env.FIRE_ENGINE_BETA_URL}/search`,
|
||||||
return response.data
|
headers: {
|
||||||
} else {
|
"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 [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user