handle errors more reliably

This commit is contained in:
sneurlax 2023-01-27 16:08:56 -06:00
parent ad5f9b3de4
commit 177eb70d51

View file

@ -188,8 +188,11 @@ class SimplexAPI {
}
final jsonArray = jsonDecode(res.body);
if (jsonArray.containsKey('error') as bool) {
if (jsonArray['error'] == true || jsonArray['error'] == 'true') {
// jsonArray['error'] as bool == true?
throw Exception('getQuote exception: ${jsonArray['error']}');
}
}
jsonArray['quote'] = quote; // Add and pass this on
@ -273,10 +276,11 @@ class SimplexAPI {
throw Exception('newOrder exception: statusCode= ${res.statusCode}');
}
final jsonArray = jsonDecode(res.body); // TODO check if valid json
if (jsonArray.containsKey('error') as bool) {
if (jsonArray['error'] == true || jsonArray['error'] == 'true') {
print('error');
throw Exception(jsonArray['message']);
}
}
SimplexOrder _order = SimplexOrder(
quote: quote,