mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 11:45:59 +00:00
fix: some exchange api error propagation
This commit is contained in:
parent
0ca5e46474
commit
0ab96ad6a1
2 changed files with 34 additions and 6 deletions
|
@ -100,12 +100,18 @@ class ChangeNowAPI {
|
||||||
body: jsonEncode(body),
|
body: jsonEncode(body),
|
||||||
);
|
);
|
||||||
|
|
||||||
final parsed = jsonDecode(response.body);
|
try {
|
||||||
|
final parsed = jsonDecode(response.body);
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
|
} catch (_) {
|
||||||
|
Logging.instance.log("ChangeNOW api failed to parse: ${response.body}",
|
||||||
|
level: LogLevel.Error);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance
|
||||||
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
.log("_makePostRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,10 +302,32 @@ abstract class TrocadorAPI {
|
||||||
final json = await _makeGetRequest(uri);
|
final json = await _makeGetRequest(uri);
|
||||||
final map = Map<String, dynamic>.from(json as Map);
|
final map = Map<String, dynamic>.from(json as Map);
|
||||||
|
|
||||||
return ExchangeResponse(value: TrocadorTradeNew.fromMap(map));
|
try {
|
||||||
|
return ExchangeResponse(value: TrocadorTradeNew.fromMap(map));
|
||||||
|
} catch (e, s) {
|
||||||
|
String error = map["error"] as String? ?? json.toString();
|
||||||
|
if (error ==
|
||||||
|
"trade could not be generated, some unknown error happened") {
|
||||||
|
error =
|
||||||
|
"This trade couldn't be completed. Please select another provider.";
|
||||||
|
}
|
||||||
|
|
||||||
|
Logging.instance.log(
|
||||||
|
"_getNewTrade failed to parse response: $json\n$e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
return ExchangeResponse(
|
||||||
|
exception: ExchangeException(
|
||||||
|
error,
|
||||||
|
ExchangeExceptionType.serializeResponseError,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance
|
Logging.instance.log(
|
||||||
.log("_getNewTrade exception: $e\n$s", level: LogLevel.Error);
|
"_getNewTrade exception: $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
return ExchangeResponse(
|
return ExchangeResponse(
|
||||||
exception: ExchangeException(
|
exception: ExchangeException(
|
||||||
e.toString(),
|
e.toString(),
|
||||||
|
|
Loading…
Reference in a new issue