From cd456d9b15939a17dd0f989dba60a59e7aa5577f Mon Sep 17 00:00:00 2001 From: Step7750 Date: Mon, 4 Nov 2024 16:59:03 -0700 Subject: [PATCH] Improves Resilience From Missing Steam Response Fields --- src/lib/alarms/trade_history.ts | 2 +- src/lib/alarms/trade_offer.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/alarms/trade_history.ts b/src/lib/alarms/trade_history.ts index 62d0a187..d1f150b5 100644 --- a/src/lib/alarms/trade_history.ts +++ b/src/lib/alarms/trade_history.ts @@ -80,7 +80,7 @@ async function getTradeHistoryFromAPI(): Promise { } const data = (await resp.json()) as TradeHistoryAPIResponse; - return data.response.trades + return (data.response?.trades || []) .filter((e) => e.status === 3) // Ensure we only count _complete_ trades (k_ETradeStatus_Complete) .filter((e) => !e.time_escrow_end || new Date(parseInt(e.time_escrow_end) * 1000).getTime() < Date.now()) .map((e) => { diff --git a/src/lib/alarms/trade_offer.ts b/src/lib/alarms/trade_offer.ts index 22539e54..5e46a0d0 100644 --- a/src/lib/alarms/trade_offer.ts +++ b/src/lib/alarms/trade_offer.ts @@ -237,7 +237,7 @@ async function getSentTradeOffersFromAPI(): Promise { } const data = (await resp.json()) as TradeOffersAPIResponse; - return data.response.trade_offers_sent.map(offerStateMapper); + return (data.response?.trade_offers_sent || []).map(offerStateMapper); } async function getSentAndReceivedTradeOffersFromAPI(): Promise<{ @@ -260,8 +260,8 @@ async function getSentAndReceivedTradeOffersFromAPI(): Promise<{ const data = (await resp.json()) as TradeOffersAPIResponse; return { - received: data.response.trade_offers_received.map(offerStateMapper), - sent: data.response.trade_offers_sent.map(offerStateMapper), + received: (data.response?.trade_offers_received || []).map(offerStateMapper), + sent: (data.response?.trade_offers_sent || []).map(offerStateMapper), steam_id: access.steam_id, }; }