Skip to content

Commit

Permalink
Merge pull request #265 from csfloat/fix/resiliance-against-missing-f…
Browse files Browse the repository at this point in the history
…ields

Improves Resilience From Missing Steam Response Fields
  • Loading branch information
Step7750 authored Nov 5, 2024
2 parents 364017d + cd456d9 commit 3ed6053
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/alarms/trade_history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function getTradeHistoryFromAPI(): Promise<TradeHistoryStatus[]> {
}

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) => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/alarms/trade_offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ async function getSentTradeOffersFromAPI(): Promise<OfferStatus[]> {
}

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<{
Expand All @@ -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,
};
}
Expand Down

0 comments on commit 3ed6053

Please sign in to comment.