mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +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),
|
||||
);
|
||||
|
||||
try {
|
||||
final parsed = jsonDecode(response.body);
|
||||
|
||||
return parsed;
|
||||
} catch (_) {
|
||||
Logging.instance.log("ChangeNOW api failed to parse: ${response.body}",
|
||||
level: LogLevel.Error);
|
||||
rethrow;
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance
|
||||
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
||||
.log("_makePostRequest($uri) threw: $e\n$s", level: LogLevel.Error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -302,10 +302,32 @@ abstract class TrocadorAPI {
|
|||
final json = await _makeGetRequest(uri);
|
||||
final map = Map<String, dynamic>.from(json as Map);
|
||||
|
||||
try {
|
||||
return ExchangeResponse(value: TrocadorTradeNew.fromMap(map));
|
||||
} catch (e, s) {
|
||||
Logging.instance
|
||||
.log("_getNewTrade exception: $e\n$s", level: LogLevel.Error);
|
||||
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) {
|
||||
Logging.instance.log(
|
||||
"_getNewTrade exception: $e\n$s",
|
||||
level: LogLevel.Error,
|
||||
);
|
||||
return ExchangeResponse(
|
||||
exception: ExchangeException(
|
||||
e.toString(),
|
||||
|
|
Loading…
Reference in a new issue