diff --git a/CHANGELOG.md b/CHANGELOG.md index e6775ab..21eae84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ CHANGELOG ## 2.0.1 (12.02.204) ## -* 🛠 Add logging framework ([#66](https://github.com/tankste/app/issues/66)) +* 🛠 Add error logging +* ➕ Add logging framework ([#66](https://github.com/tankste/app/issues/66)) * 🐞 Fix initial state hangup ([#64](https://github.com/tankste/app/issues/64)) ## 2.0.0 (29.01.2024) ## diff --git a/app/pubspec.yaml b/app/pubspec.yaml index d11d110..abdd4f4 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -2,7 +2,7 @@ name: tankste description: Finde die günstigste Tankstelle in deiner Nähe! publish_to: 'none' -version: 2.0.1+26 +version: 2.0.1+27 environment: sdk: ">=2.19.6 <3.0.0" diff --git a/core/lib/log/log.dart b/core/lib/log/log.dart index 6a73cb2..b089cbd 100644 --- a/core/lib/log/log.dart +++ b/core/lib/log/log.dart @@ -35,4 +35,8 @@ class Log { static void e(String message) { _logger.e(message); } + + static void exception(Exception exception) { + _logger.t(exception); + } } diff --git a/sponsor/lib/repository/balance_repository.dart b/sponsor/lib/repository/balance_repository.dart index ba22ff1..f51e069 100644 --- a/sponsor/lib/repository/balance_repository.dart +++ b/sponsor/lib/repository/balance_repository.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'package:core/log/log.dart'; import 'package:http/http.dart' as http; import 'package:multiple_result/multiple_result.dart'; import 'package:sponsor/model/balance_model.dart'; @@ -39,7 +40,9 @@ class TanksteWebBalanceRepository extends BalanceRepository { Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; @@ -55,9 +58,12 @@ class TanksteWebBalanceRepository extends BalanceRepository { return Result.success(balance); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } diff --git a/sponsor/lib/repository/comment_repository.dart b/sponsor/lib/repository/comment_repository.dart index 330defb..c4f66e8 100644 --- a/sponsor/lib/repository/comment_repository.dart +++ b/sponsor/lib/repository/comment_repository.dart @@ -2,13 +2,12 @@ import 'dart:async'; import 'dart:convert'; import 'package:core/device/model/device_model.dart'; import 'package:core/device/repository/device_repository.dart'; +import 'package:core/log/log.dart'; import 'package:http/http.dart' as http; import 'package:multiple_result/multiple_result.dart'; -import 'package:sponsor/model/balance_model.dart'; import 'package:sponsor/model/comment_model.dart'; import 'package:sponsor/model/config_model.dart'; import 'package:sponsor/repository/config_repository.dart'; -import 'package:sponsor/repository/dto/balance_dto.dart'; import 'package:sponsor/repository/dto/comment_dto.dart'; abstract class CommentRepository { @@ -53,7 +52,9 @@ class TanksteWebCommentRepository extends CommentRepository { Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; @@ -69,9 +70,12 @@ class TanksteWebCommentRepository extends CommentRepository { return Result.success(comments); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } @@ -88,14 +92,18 @@ class TanksteWebCommentRepository extends CommentRepository { Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; Result deviceResult = await _deviceRepository.get().first; if (deviceResult.isError()) { - return Result.error(deviceResult.tryGetError()!); + Exception error = deviceResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } DeviceModel device = deviceResult.tryGetSuccess()!; @@ -111,9 +119,12 @@ class TanksteWebCommentRepository extends CommentRepository { return Result.success(comment); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } @@ -137,14 +148,18 @@ class TanksteWebCommentRepository extends CommentRepository { Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; Result deviceResult = await _deviceRepository.get().first; if (deviceResult.isError()) { - return Result.error(deviceResult.tryGetError()!); + Exception error = deviceResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } DeviceModel device = deviceResult.tryGetSuccess()!; @@ -160,7 +175,9 @@ class TanksteWebCommentRepository extends CommentRepository { return Result.success(comment); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { return Result.error(e); diff --git a/sponsor/lib/repository/config_repository.dart b/sponsor/lib/repository/config_repository.dart index 29f4965..8ac24be 100644 --- a/sponsor/lib/repository/config_repository.dart +++ b/sponsor/lib/repository/config_repository.dart @@ -1,3 +1,4 @@ +import 'package:core/log/log.dart'; import 'package:multiple_result/multiple_result.dart'; import 'package:sponsor/model/config_model.dart'; import 'package:core/config/model/config_model.dart' as core; @@ -36,6 +37,7 @@ class LocalConfigRepository extends ConfigRepository { apiBaseUrl: jsonStationConfig["apiBaseUrl"] ?? "", )); } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } diff --git a/sponsor/lib/repository/product_repository.dart b/sponsor/lib/repository/product_repository.dart index 06fea94..47c659e 100644 --- a/sponsor/lib/repository/product_repository.dart +++ b/sponsor/lib/repository/product_repository.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:core/device/model/device_model.dart'; import 'package:core/device/repository/device_repository.dart'; +import 'package:core/log/log.dart'; import 'package:in_app_purchase/in_app_purchase.dart'; import 'package:in_app_purchase_android/in_app_purchase_android.dart'; import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart'; @@ -72,15 +73,19 @@ class MobileProductRepository extends ProductRepository { Future> _getAsync(String id) async { try { if (!await InAppPurchase.instance.isAvailable()) { - return Result.error(Exception("InAppPurchase is not available")); + Exception error = Exception("InAppPurchase is not available"); + Log.exception(error); + return Result.error(error); } final ProductDetailsResponse response = await InAppPurchase.instance.queryProductDetails({id}); if (response.notFoundIDs.isNotEmpty) { - return Result.error(Exception( - "Product '$id' not found. Reason: ${response.error?.message}")); + Exception error = Exception( + "Product '$id' not found. Reason: ${response.error?.message}"); + Log.exception(error); + return Result.error(error); } ProductDetails productDto = response.productDetails.first; @@ -93,6 +98,7 @@ class MobileProductRepository extends ProductRepository { ); return Result.success(product); } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } @@ -115,7 +121,9 @@ class MobileProductRepository extends ProductRepository { Future> _purchaseAsync(String id) async { try { if (!await InAppPurchase.instance.isAvailable()) { - return Result.error(Exception("InAppPurchase is not available")); + Exception error = Exception("InAppPurchase is not available"); + Log.exception(error); + return Result.error(error); } final ProductDetailsResponse response = @@ -125,7 +133,9 @@ class MobileProductRepository extends ProductRepository { Result deviceResult = await _deviceRepository.get().first; if (deviceResult.isError()) { - return Result.error(deviceResult.tryGetError()!); + Exception error = Exception(deviceResult.tryGetError()!); + Log.exception(error); + return Result.error(error); } DeviceModel device = deviceResult.tryGetSuccess()!; @@ -166,9 +176,12 @@ class MobileProductRepository extends ProductRepository { provider: PurchaseProvider.appleStore)) .first; } else { - return Result.error(Exception("Unsupported purchase details!")); + Exception error = Exception("Unsupported purchase details!"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } @@ -186,7 +199,9 @@ class MobileProductRepository extends ProductRepository { Future> _restoreAsync() async { try { if (!await InAppPurchase.instance.isAvailable()) { - return Result.error(Exception("InAppPurchase is not available")); + Exception error = Exception("InAppPurchase is not available"); + Log.exception(error); + return Result.error(error); } InAppPurchase.instance.restorePurchases(); @@ -201,7 +216,9 @@ class MobileProductRepository extends ProductRepository { if (purchaseDetails is GooglePlayPurchaseDetails) { // TODO // This is not required for Google. But be fair and add this later :-) - return Result.error(Exception("Unsupported purchase details!")); + Exception error = Exception("Unsupported purchase details!"); + Log.exception(error); + return Result.error(error); } else if (purchaseDetails is AppStorePurchaseDetails) { String transactionId = purchaseDetails.skPaymentTransaction .originalTransaction?.transactionIdentifier ?? @@ -210,9 +227,12 @@ class MobileProductRepository extends ProductRepository { .registerByAppleTransactionId(transactionId) .first; } else { - return Result.error(Exception("Unsupported purchase details!")); + Exception error = Exception("Unsupported purchase details!"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } @@ -240,8 +260,9 @@ class MobileProductRepository extends ProductRepository { await InAppPurchase.instance.completePurchase(purchaseDetails); } - return Result.error( - Exception("Purchase error: ${purchaseDetails.error}")); + Exception error = Exception("Purchase error: ${purchaseDetails.error}"); + Log.exception(error); + return Result.error(error); case PurchaseStatus.restored: if (purchaseDetails.pendingCompletePurchase && Platform.isIOS) { await InAppPurchase.instance.completePurchase(purchaseDetails); @@ -253,9 +274,12 @@ class MobileProductRepository extends ProductRepository { await InAppPurchase.instance.completePurchase(purchaseDetails); } - return Result.error(Exception("Purchase error: Canceled")); + Exception error = Exception("Purchase error: Canceled"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } diff --git a/sponsor/lib/repository/purchase_repository.dart b/sponsor/lib/repository/purchase_repository.dart index d6e7c94..0d798b6 100644 --- a/sponsor/lib/repository/purchase_repository.dart +++ b/sponsor/lib/repository/purchase_repository.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:core/device/model/device_model.dart'; import 'package:core/device/repository/device_repository.dart'; +import 'package:core/log/log.dart'; import 'package:multiple_result/multiple_result.dart'; import 'package:http/http.dart' as http; import 'package:sponsor/model/apple_purchase_model.dart'; @@ -49,14 +50,18 @@ class TanksteWebPurchaseRepository extends PurchaseRepository { Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; Result deviceResult = await _deviceRepository.get().first; if (deviceResult.isError()) { - return Result.error(deviceResult.tryGetError()!); + Exception error = deviceResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } DeviceModel device = deviceResult.tryGetSuccess()!; @@ -68,7 +73,9 @@ class TanksteWebPurchaseRepository extends PurchaseRepository { } else if (purchase is ApplePurchaseModel) { body = jsonEncode(ApplePurchaseDto.fromModel(purchase, device.id)); } else { - return Result.error(Exception("Unsupported purchase type!")); + Exception error = Exception("Unsupported purchase type!"); + Log.exception(error); + return Result.error(error); } http.Response response = await http.post(url, body: body, headers: { @@ -86,14 +93,19 @@ class TanksteWebPurchaseRepository extends PurchaseRepository { ApplePurchaseDto.fromJson(jsonResponse); purchaseResult = applePurchaseDto.toModel(); } else { - return Result.error(Exception("Unsupported purchase type!")); + Exception error = Exception("Unsupported purchase type!"); + Log.exception(error); + return Result.error(error); } return Result.success(purchaseResult); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } diff --git a/sponsor/lib/repository/sponsorship_repository.dart b/sponsor/lib/repository/sponsorship_repository.dart index 154c04f..c65a048 100644 --- a/sponsor/lib/repository/sponsorship_repository.dart +++ b/sponsor/lib/repository/sponsorship_repository.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:core/log/log.dart'; import 'package:http/http.dart' as http; import 'package:core/device/model/device_model.dart'; import 'package:core/device/repository/device_repository.dart'; @@ -45,14 +46,18 @@ class TanksteWebSponsorshipRepository extends SponsorshipRepository { Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; Result deviceResult = await _deviceRepository.get().first; if (deviceResult.isError()) { - return Result.error(deviceResult.tryGetError()!); + Exception error = deviceResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } DeviceModel device = deviceResult.tryGetSuccess()!; @@ -68,9 +73,12 @@ class TanksteWebSponsorshipRepository extends SponsorshipRepository { return Result.success(sponsorship); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } } diff --git a/sponsor/lib/repository/transaction_device_repository.dart b/sponsor/lib/repository/transaction_device_repository.dart index 6bdcf5b..14481c0 100644 --- a/sponsor/lib/repository/transaction_device_repository.dart +++ b/sponsor/lib/repository/transaction_device_repository.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; +import 'package:core/log/log.dart'; import 'package:http/http.dart' as http; import 'package:core/device/model/device_model.dart'; import 'package:core/device/repository/device_repository.dart'; @@ -51,7 +52,9 @@ class TanksteWebTransactionDeviceRepository Result configResult = await _configRepository.get().first; if (configResult.isError()) { - return Result.error(configResult.tryGetError()!); + Exception error = configResult.tryGetError()!; + Log.exception(error); + return Result.error(error); } ConfigModel config = configResult.tryGetSuccess()!; @@ -68,9 +71,12 @@ class TanksteWebTransactionDeviceRepository return Result.success(device); } else { - return Result.error(Exception("API Error!\n\n${response.body}")); + Exception error = Exception("API Error!\n\n${response.body}"); + Log.exception(error); + return Result.error(error); } } on Exception catch (e) { + Log.exception(e); return Result.error(e); } }