feat: catch hltb error

This commit is contained in:
Zamitto 2024-08-31 14:17:03 -03:00
parent 567d9f540d
commit 158b878883

View file

@ -2,6 +2,7 @@ import axios from "axios";
import { requestWebPage } from "@main/helpers";
import { HowLongToBeatCategory } from "@types";
import { formatName } from "@shared";
import { logger } from "./logger";
export interface HowLongToBeatResult {
game_id: number;
@ -13,7 +14,8 @@ export interface HowLongToBeatSearchResponse {
}
export const searchHowLongToBeat = async (gameName: string) => {
const response = await axios.post(
const response = await axios
.post(
"https://howlongtobeat.com/api/search",
{
searchType: "games",
@ -28,7 +30,11 @@ export const searchHowLongToBeat = async (gameName: string) => {
Referer: "https://howlongtobeat.com/",
},
}
);
)
.catch((error) => {
logger.error("Error searching HowLongToBeat:", error?.response?.status);
return { data: { data: [] } };
});
return response.data as HowLongToBeatSearchResponse;
};