mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: catch hltb error
This commit is contained in:
parent
567d9f540d
commit
158b878883
1 changed files with 21 additions and 15 deletions
|
@ -2,6 +2,7 @@ import axios from "axios";
|
||||||
import { requestWebPage } from "@main/helpers";
|
import { requestWebPage } from "@main/helpers";
|
||||||
import { HowLongToBeatCategory } from "@types";
|
import { HowLongToBeatCategory } from "@types";
|
||||||
import { formatName } from "@shared";
|
import { formatName } from "@shared";
|
||||||
|
import { logger } from "./logger";
|
||||||
|
|
||||||
export interface HowLongToBeatResult {
|
export interface HowLongToBeatResult {
|
||||||
game_id: number;
|
game_id: number;
|
||||||
|
@ -13,22 +14,27 @@ export interface HowLongToBeatSearchResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const searchHowLongToBeat = async (gameName: string) => {
|
export const searchHowLongToBeat = async (gameName: string) => {
|
||||||
const response = await axios.post(
|
const response = await axios
|
||||||
"https://howlongtobeat.com/api/search",
|
.post(
|
||||||
{
|
"https://howlongtobeat.com/api/search",
|
||||||
searchType: "games",
|
{
|
||||||
searchTerms: formatName(gameName).split(" "),
|
searchType: "games",
|
||||||
searchPage: 1,
|
searchTerms: formatName(gameName).split(" "),
|
||||||
size: 100,
|
searchPage: 1,
|
||||||
},
|
size: 100,
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
"User-Agent":
|
|
||||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
|
||||||
Referer: "https://howlongtobeat.com/",
|
|
||||||
},
|
},
|
||||||
}
|
{
|
||||||
);
|
headers: {
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
||||||
|
Referer: "https://howlongtobeat.com/",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((error) => {
|
||||||
|
logger.error("Error searching HowLongToBeat:", error?.response?.status);
|
||||||
|
return { data: { data: [] } };
|
||||||
|
});
|
||||||
|
|
||||||
return response.data as HowLongToBeatSearchResponse;
|
return response.data as HowLongToBeatSearchResponse;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue