Skip to content

Commit 3ef3608

Browse files
authored
Fixed errors for setting some properties if an API response is empty (#64)
1 parent 0a721d8 commit 3ef3608

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

js/gameProperties.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function getGameProperties(appInfoDirect, appInfoSteamUser, appInfo
6161
}
6262

6363
function getGameNameProperty(nameProperty, appInfoSteamUser, outputProperties) {
64-
if (!nameProperty.enabled || !appInfoSteamUser.name) { return outputProperties; }
64+
if (!nameProperty.enabled || !appInfoSteamUser?.name) { return outputProperties; }
6565

6666
// We use the title from the Steam User API as this stops us from always having to ping the Steam Store API, as most users will want to get the game name
6767
const gameTitle = appInfoSteamUser.name;
@@ -86,12 +86,12 @@ function getGameNameProperty(nameProperty, appInfoSteamUser, outputProperties) {
8686

8787
function getGameCoverImage(coverProperty, appInfoDirect, appInfoSteamUser) {
8888
// Don't set a cover image if it is disabled, or if there is no cover image available
89-
if (!coverProperty.enabled || (!appInfoDirect.header_image && !appInfoSteamUser.header_image?.english && !coverProperty.default)) { return null; }
89+
if (!coverProperty.enabled || (!appInfoDirect?.header_image && !appInfoSteamUser?.header_image?.english && !coverProperty.default)) { return null; }
9090

9191
// Use the URL from the Steam Store API if available, else use the SteamUser API if available, else use the default image
92-
const coverUrl = appInfoDirect.header_image
92+
const coverUrl = appInfoDirect?.header_image
9393
? appInfoDirect.header_image
94-
: (appInfoSteamUser.header_image?.english
94+
: (appInfoSteamUser?.header_image?.english
9595
? `https://cdn.cloudflare.steamstatic.com/steam/apps/${appInfoSteamUser.gameid}/${appInfoSteamUser.header_image.english}`
9696
: coverProperty.default);
9797

@@ -104,7 +104,7 @@ function getGameCoverImage(coverProperty, appInfoDirect, appInfoSteamUser) {
104104
}
105105

106106
function getGameIcon(iconProperty, appInfoSteamUser) {
107-
if (!iconProperty.enabled || (!appInfoSteamUser.icon && !iconProperty.default)) { return null; }
107+
if (!iconProperty.enabled || (!appInfoSteamUser?.icon && !iconProperty.default)) { return null; }
108108

109109
// Game icon URL is not available through the Steam Store API, so we have to use the SteamUser API
110110
const iconUrl = appInfoSteamUser.icon
@@ -124,7 +124,7 @@ function getGameReleaseDate(releaseDateProperty, appInfoDirect, outputProperties
124124

125125
// Note: If no release date is available, we don't set it at all in the database
126126
let releaseDate;
127-
if (appInfoDirect.release_date?.date) {
127+
if (appInfoDirect?.release_date?.date) {
128128
// We need to distinguish three cases: Only the year is given ('2023'), year and month ('March 2023'), or year, month and day ('13 Mar, 2023')
129129
// In cases where data is missing, we add the last day of the year or the first day of the month (as the last day of the month differs between months)
130130
// We always add 00:00 UTC as the time, as the date is always given in UTC and we don't want to convert it to the local timezone
@@ -217,7 +217,7 @@ async function getGameTags(tagsProperty, appInfoSteamUser, outputProperties) {
217217
if (!tagsProperty.enabled) { return outputProperties; }
218218

219219
// The tags are not available through the Steam Store API, so we have to use the SteamUser API instead
220-
const tags = appInfoSteamUser.store_tags
220+
const tags = appInfoSteamUser?.store_tags
221221
? await getSteamTagNames(appInfoSteamUser.store_tags, tagsProperty.tagLanguage).then((tags) => { return tags; })
222222
: null;
223223

@@ -236,7 +236,7 @@ async function getGameTags(tagsProperty, appInfoSteamUser, outputProperties) {
236236

237237
function getGameDescription(gameDescriptionProperty, appInfoDirect, outputProperties) {
238238
// Set no description if the value doesn't exist in the Steam Store API response, or it is an empty string
239-
if (!gameDescriptionProperty.enabled || !appInfoDirect.short_description) { return outputProperties; }
239+
if (!gameDescriptionProperty.enabled || !appInfoDirect?.short_description) { return outputProperties; }
240240

241241
// Notion limits text fields to 2000 characters
242242
const gameDescription = appInfoDirect.short_description.substring(0, 2000);
@@ -265,7 +265,7 @@ function getGameStorePage(storePageProperty, steamAppId, outputProperties) {
265265
}
266266

267267
function getGamePrice(priceProperty, appInfoDirect, outputProperties) {
268-
if (!priceProperty.enabled || appInfoDirect.price_overview?.initial === undefined || appInfoDirect.price_overview?.initial === null) { return outputProperties; }
268+
if (!priceProperty.enabled || appInfoDirect?.price_overview?.initial === undefined || appInfoDirect?.price_overview?.initial === null) { return outputProperties; }
269269

270270
const price = appInfoDirect.price_overview.initial / 100;
271271

@@ -280,7 +280,7 @@ function getSteamDeckCompatibility(steamDeckCompatibilityProperty, appInfoSteamU
280280
if (!steamDeckCompatibilityProperty.enabled) { return outputProperties; }
281281

282282
let compatibility = "Unknown";
283-
switch (appInfoSteamUser.steam_deck_compatibility?.category) {
283+
switch (appInfoSteamUser?.steam_deck_compatibility?.category) {
284284
case "1":
285285
compatibility = "Unsupported";
286286
break;
@@ -304,7 +304,7 @@ function getSteamDeckCompatibility(steamDeckCompatibilityProperty, appInfoSteamU
304304
}
305305

306306
function getGameDevelopers(developerProperty, appInfoDirect, outputProperties) {
307-
if (!developerProperty.enabled || !appInfoDirect.developers) { return outputProperties; }
307+
if (!developerProperty.enabled || !appInfoDirect?.developers) { return outputProperties; }
308308

309309
// Output property is multi-select, as games can have multiple developers in the API
310310
outputProperties[developerProperty.notionProperty] = {
@@ -319,7 +319,7 @@ function getGameDevelopers(developerProperty, appInfoDirect, outputProperties) {
319319
}
320320

321321
function getGamePublishers(publisherProperty, appInfoDirect, outputProperties) {
322-
if (!publisherProperty.enabled || !appInfoDirect.publishers) { return outputProperties; }
322+
if (!publisherProperty.enabled || !appInfoDirect?.publishers) { return outputProperties; }
323323

324324
// Output property is multi-select, as games can have multiple publishers in the API
325325
outputProperties[publisherProperty.notionProperty] = {

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,7 +1,7 @@
11
{
22
"name": "notion-steam-api-integration",
33
"type": "module",
4-
"version": "1.9.0",
4+
"version": "1.9.1",
55
"description": "Notion integration to fetch data from the Steam API and populate a database given Steam App ID's.",
66
"main": "index.js",
77
"dependencies": {

0 commit comments

Comments
 (0)