mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
added new changenow custom exception
This commit is contained in:
parent
cc58379f3b
commit
9a222544ba
2 changed files with 31 additions and 3 deletions
|
@ -0,0 +1,7 @@
|
||||||
|
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
||||||
|
|
||||||
|
class UnsupportedCurrencyException extends ExchangeException {
|
||||||
|
UnsupportedCurrencyException(super.message, super.type, this.currency);
|
||||||
|
|
||||||
|
final String currency;
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
||||||
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
||||||
|
import 'package:stackwallet/exceptions/exchange/unsupported_currency_exception.dart';
|
||||||
import 'package:stackwallet/external_api_keys.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/cn_exchange_estimate.dart';
|
||||||
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart';
|
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart';
|
||||||
|
@ -49,9 +50,16 @@ class ChangeNowAPI {
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
final parsed = jsonDecode(response.body);
|
final parsed = jsonDecode(response.body);
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
|
} on FormatException catch (e) {
|
||||||
|
return {
|
||||||
|
"error": "Dart format exception",
|
||||||
|
"message": response.body,
|
||||||
|
};
|
||||||
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
||||||
|
@ -207,7 +215,20 @@ class ChangeNowAPI {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// json array is expected here
|
// json array is expected here
|
||||||
final jsonArray = (await _makeGetRequest(uri)) as List;
|
|
||||||
|
final response = await _makeGetRequest(uri);
|
||||||
|
|
||||||
|
if (response is Map && response["error"] != null) {
|
||||||
|
return ExchangeResponse(
|
||||||
|
exception: UnsupportedCurrencyException(
|
||||||
|
response["message"] as String? ?? response["error"].toString(),
|
||||||
|
ExchangeExceptionType.generic,
|
||||||
|
ticker,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final jsonArray = response as List;
|
||||||
|
|
||||||
List<Currency> currencies = [];
|
List<Currency> currencies = [];
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue