From 4cbf8b8cd95aff24165e1c6acaebe9d3f8902ca1 Mon Sep 17 00:00:00 2001 From: julian Date: Sat, 4 Feb 2023 11:15:42 -0600 Subject: [PATCH] refactor exchange exception --- lib/exceptions/exchange/exchange_exception.dart | 13 +++++++++++++ .../exchange/majestic_bank/mb_exception.dart | 5 +++++ .../exchange/change_now/change_now_api.dart | 1 + .../exchange/exchange_data_loading_service.dart | 6 +++--- lib/services/exchange/exchange_response.dart | 13 +------------ .../exchange/majestic_bank/majestic_bank_api.dart | 1 + .../exchange/simpleswap/simpleswap_api.dart | 1 + 7 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 lib/exceptions/exchange/exchange_exception.dart create mode 100644 lib/exceptions/exchange/majestic_bank/mb_exception.dart diff --git a/lib/exceptions/exchange/exchange_exception.dart b/lib/exceptions/exchange/exchange_exception.dart new file mode 100644 index 000000000..af7aa8f65 --- /dev/null +++ b/lib/exceptions/exchange/exchange_exception.dart @@ -0,0 +1,13 @@ +import 'package:stackwallet/exceptions/sw_exception.dart'; + +enum ExchangeExceptionType { generic, serializeResponseError } + +class ExchangeException extends SWException { + ExchangeExceptionType type; + ExchangeException(super.message, this.type); + + @override + String toString() { + return message; + } +} diff --git a/lib/exceptions/exchange/majestic_bank/mb_exception.dart b/lib/exceptions/exchange/majestic_bank/mb_exception.dart new file mode 100644 index 000000000..d3130d874 --- /dev/null +++ b/lib/exceptions/exchange/majestic_bank/mb_exception.dart @@ -0,0 +1,5 @@ +import 'package:stackwallet/exceptions/exchange/exchange_exception.dart'; + +class MBException extends ExchangeException { + MBException(super.message, super.type); +} diff --git a/lib/services/exchange/change_now/change_now_api.dart b/lib/services/exchange/change_now/change_now_api.dart index d957eaf1a..a9920bfb8 100644 --- a/lib/services/exchange/change_now/change_now_api.dart +++ b/lib/services/exchange/change_now/change_now_api.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:decimal/decimal.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; +import 'package:stackwallet/exceptions/exchange/exchange_exception.dart'; import 'package:stackwallet/external_api_keys.dart'; import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart'; import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart'; diff --git a/lib/services/exchange/exchange_data_loading_service.dart b/lib/services/exchange/exchange_data_loading_service.dart index d06f8b726..8d232e957 100644 --- a/lib/services/exchange/exchange_data_loading_service.dart +++ b/lib/services/exchange/exchange_data_loading_service.dart @@ -55,7 +55,7 @@ class ExchangeDataLoadingService { } } else { Logging.instance.log( - "Failed to load changeNOW fixed rate markets: ${response3.exception?.errorMessage}", + "Failed to load changeNOW fixed rate markets: ${response3.exception?.message}", level: LogLevel.Error); ref.read(changeNowFixedInitialLoadStatusStateProvider.state).state = @@ -122,7 +122,7 @@ class ExchangeDataLoadingService { } } else { Logging.instance.log( - "Failed to load changeNOW available floating rate pairs: ${response2.exception?.errorMessage}", + "Failed to load changeNOW available floating rate pairs: ${response2.exception?.message}", level: LogLevel.Error); ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state = ChangeNowLoadStatus.failed; @@ -130,7 +130,7 @@ class ExchangeDataLoadingService { } } else { Logging.instance.log( - "Failed to load changeNOW currencies: ${response.exception?.errorMessage}", + "Failed to load changeNOW currencies: ${response.exception?.message}", level: LogLevel.Error); await Future.delayed(const Duration(seconds: 3)); ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state = diff --git a/lib/services/exchange/exchange_response.dart b/lib/services/exchange/exchange_response.dart index 59441fb9b..79339e5f7 100644 --- a/lib/services/exchange/exchange_response.dart +++ b/lib/services/exchange/exchange_response.dart @@ -1,15 +1,4 @@ -enum ExchangeExceptionType { generic, serializeResponseError } - -class ExchangeException implements Exception { - String errorMessage; - ExchangeExceptionType type; - ExchangeException(this.errorMessage, this.type); - - @override - String toString() { - return errorMessage; - } -} +import 'package:stackwallet/exceptions/exchange/exchange_exception.dart'; class ExchangeResponse { late final T? value; diff --git a/lib/services/exchange/majestic_bank/majestic_bank_api.dart b/lib/services/exchange/majestic_bank/majestic_bank_api.dart index da68db574..e140e5308 100644 --- a/lib/services/exchange/majestic_bank/majestic_bank_api.dart +++ b/lib/services/exchange/majestic_bank/majestic_bank_api.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:decimal/decimal.dart'; import 'package:http/http.dart' as http; +import 'package:stackwallet/exceptions/exchange/exchange_exception.dart'; import 'package:stackwallet/models/exchange/majestic_bank/mb_limit.dart'; import 'package:stackwallet/models/exchange/majestic_bank/mb_order.dart'; import 'package:stackwallet/models/exchange/majestic_bank/mb_order_calculation.dart'; diff --git a/lib/services/exchange/simpleswap/simpleswap_api.dart b/lib/services/exchange/simpleswap/simpleswap_api.dart index 3d626b2eb..bd6e933fe 100644 --- a/lib/services/exchange/simpleswap/simpleswap_api.dart +++ b/lib/services/exchange/simpleswap/simpleswap_api.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:decimal/decimal.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; +import 'package:stackwallet/exceptions/exchange/exchange_exception.dart'; import 'package:stackwallet/external_api_keys.dart'; import 'package:stackwallet/models/exchange/response_objects/fixed_rate_market.dart'; import 'package:stackwallet/models/exchange/response_objects/pair.dart';