Skip to content

Commit

Permalink
error handling added to throw error on empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
yashkathe committed Dec 29, 2022
1 parent 3ff1d35 commit d403269
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "f1-api-node",
"version": "0.2.2",
"version": "0.3.0",
"description": "A simple library written in typescript to fetch Formula-1 data",
"main": "dist/server.js",
"types": "dist/server.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/scraper/constructors-standings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const getConstructorStandings = async (year: number = new Date().getFullY
constructorStandings.push(constructorStanding);
}
});
if (constructorStandings.length === 0) {
throw new Error(" No data found");
}
return constructorStandings;
} catch (error: any) {
throw new Error(error);
Expand Down
3 changes: 3 additions & 0 deletions src/scraper/driver-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const getDriverData = async (): Promise<isDriver[]> => {
drivers.push(driver);
}
});
if (drivers.length === 0) {
throw new Error(" No data found");
}
return drivers;
} catch (error: any) {
throw new Error(error);
Expand Down
3 changes: 3 additions & 0 deletions src/scraper/driver-standings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const getDriverStandings = async (year: number = new Date().getFullYear()
driverStandings.push(driverStanding);
}
});
if (driverStandings.length === 0) {
throw new Error(" No data found");
}
return driverStandings;
} catch (error: any) {
throw new Error(error);
Expand Down
3 changes: 3 additions & 0 deletions src/scraper/race-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const getRaceResults = async (year: number): Promise<isRaceResult[]> => {
raceResults.push(raceResult);
}
});
if (raceResults.length === 0) {
throw new Error(" No data found");
}
return raceResults;
} catch (error: any) {
throw new Error(error);
Expand Down
3 changes: 3 additions & 0 deletions src/scraper/team-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const getTeamsData = async (): Promise<isTeam[]> => {
teams.push(team);
}
});
if (teams.length === 0) {
throw new Error(" No data found");
}
return teams;
} catch (error: any) {
throw new Error(error);
Expand Down
3 changes: 3 additions & 0 deletions src/scraper/world-champions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const getWorldChampions = async (): Promise<isHallOfFame[]> => {
worldChampions.push(worldChampion);
}
});
if (worldChampions.length === 0) {
throw new Error(" No data found");
}
return worldChampions;
} catch (error: any) {
throw new Error(error);
Expand Down

0 comments on commit d403269

Please sign in to comment.