Skip to content

Commit

Permalink
refactor: optimize getGamesJapan
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Aug 21, 2022
1 parent e6ad25f commit 70c61cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/lib/getGames/getGamesJapan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { JP_GET_GAMES_URL } from '../utils/constants';
import type { GameJP } from '../utils/interfaces';
import { EshopError } from '../utils/utils';

const parser = new XMLParser();

/**
* Fetches all games on japanese eShops
*
Expand All @@ -17,15 +19,11 @@ export const getGamesJapan = async (): Promise<GameJP[]> => {
throw new EshopError('Fetching of JP Games failed');
}

const parser = new XMLParser();

const gamesJP = Result.from(parser.parse(response.unwrap()));
const gamesJP = Result.from(() => parser.parse(response.unwrap()));

if (gamesJP.isErr()) {
throw new EshopError('Parsing of JP Games failed');
}

const allGamesJP: GameJP[] = gamesJP.unwrap().TitleInfoList.TitleInfo;

return allGamesJP;
return gamesJP.unwrap().TitleInfoList.TitleInfo as GameJP[];
};

0 comments on commit 70c61cd

Please sign in to comment.