Skip to content

Commit d403269

Browse files
committed
error handling added to throw error on empty arrays
1 parent 3ff1d35 commit d403269

File tree

8 files changed

+21
-3
lines changed

8 files changed

+21
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "f1-api-node",
3-
"version": "0.2.2",
3+
"version": "0.3.0",
44
"description": "A simple library written in typescript to fetch Formula-1 data",
55
"main": "dist/server.js",
66
"types": "dist/server.d.ts",

src/scraper/constructors-standings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const getConstructorStandings = async (year: number = new Date().getFullY
2626
constructorStandings.push(constructorStanding);
2727
}
2828
});
29+
if (constructorStandings.length === 0) {
30+
throw new Error(" No data found");
31+
}
2932
return constructorStandings;
3033
} catch (error: any) {
3134
throw new Error(error);

src/scraper/driver-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export const getDriverData = async (): Promise<isDriver[]> => {
3535
drivers.push(driver);
3636
}
3737
});
38+
if (drivers.length === 0) {
39+
throw new Error(" No data found");
40+
}
3841
return drivers;
3942
} catch (error: any) {
4043
throw new Error(error);

src/scraper/driver-standings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const getDriverStandings = async (year: number = new Date().getFullYear()
3232
driverStandings.push(driverStanding);
3333
}
3434
});
35+
if (driverStandings.length === 0) {
36+
throw new Error(" No data found");
37+
}
3538
return driverStandings;
3639
} catch (error: any) {
3740
throw new Error(error);

src/scraper/race-results.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const getRaceResults = async (year: number): Promise<isRaceResult[]> => {
3232
raceResults.push(raceResult);
3333
}
3434
});
35+
if (raceResults.length === 0) {
36+
throw new Error(" No data found");
37+
}
3538
return raceResults;
3639
} catch (error: any) {
3740
throw new Error(error);

src/scraper/team-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export const getTeamsData = async (): Promise<isTeam[]> => {
4040
teams.push(team);
4141
}
4242
});
43+
if (teams.length === 0) {
44+
throw new Error(" No data found");
45+
}
4346
return teams;
4447
} catch (error: any) {
4548
throw new Error(error);

src/scraper/world-champions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export const getWorldChampions = async (): Promise<isHallOfFame[]> => {
3737
worldChampions.push(worldChampion);
3838
}
3939
});
40+
if (worldChampions.length === 0) {
41+
throw new Error(" No data found");
42+
}
4043
return worldChampions;
4144
} catch (error: any) {
4245
throw new Error(error);

0 commit comments

Comments
 (0)