Skip to content

Commit

Permalink
fix: Avoid type casting 204 return types from API (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
marfavi authored May 27, 2023
1 parent 82c5bc3 commit 75a22dc
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,9 @@ class ReceiptRemoteDataSource {

/// Retrieves all of the users purchase receipts
Future<Either<Failure, List<Receipt>>> getUserPurchasesReceipts() async {
// The API CAN return null if the user has no tickets,
// but the generator doesn't pick up on this, hence the type parameter
return executor<List<SimplePurchaseResponse>?>(
apiV2.apiV2PurchasesGet,
).bindFuture((result) {
// If the user has no purchases, the API returns 204 No Content (body is
// null). The generator is bad and doesn't handle this case
if (result == null) return List<Receipt>.empty();
return result
.map(PurchaseReceiptModel.fromSimplePurchaseResponse)
.toList();
});
return executor(apiV2.apiV2PurchasesGet).bindFuture(
(result) =>
result.map(PurchaseReceiptModel.fromSimplePurchaseResponse).toList(),
);
}
}

0 comments on commit 75a22dc

Please sign in to comment.