Skip to content

Commit

Permalink
better error handling for missing price table entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk committed Apr 9, 2024
1 parent 59770e7 commit 24a0aa1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/controllers/fetch/price_tables_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,25 @@ class PriceTablesController extends GetxController with WidgetsBindingObserver {
priceTableDateUTC.subtract(const Duration(hours: 6)));
}

return priceTables.priceTableMap[priceTableDateString]!.data[assetType]
?.entries[assetId];
final PriceTable? priceTable =
priceTables.priceTableMap[priceTableDateString];
if (priceTable == null) {
throw Exception('Price table for $priceTableDateString not found.');
} else {
final PriceTableEntries? assetData = priceTable.data[assetType];
if (assetData == null) {
throw Exception(
'Asset type $assetType not found in $priceTableDateString.');
} else {
final double? entry = assetData.entries[assetId];
if (entry == null) {
throw Exception(
'Entry with assetId $assetId is null in $priceTableDateString.');
} else {
return entry;
}
}
}
}
}
}

0 comments on commit 24a0aa1

Please sign in to comment.