fix cart, fix log cart

This commit is contained in:
Phuoc Nguyen
2025-12-11 16:39:25 +07:00
parent e3632d4445
commit fc6a4f038e
4 changed files with 65 additions and 44 deletions

View File

@@ -138,7 +138,15 @@ class ProductsRemoteDataSource {
throw Exception('Product not found: $itemCode');
}
return ProductModel.fromJson(message as Map<String, dynamic>);
// Handle API error response: {success: false, message: "Item not found"}
if (message is Map<String, dynamic>) {
if (message['success'] == false) {
throw Exception(message['message'] ?? 'Product not found: $itemCode');
}
return ProductModel.fromJson(message);
}
throw Exception('Invalid response format for product: $itemCode');
} on DioException catch (e) {
if (e.response?.statusCode == 404) {
throw Exception('Product not found: $itemCode');