fix: some exchange api error propagation

This commit is contained in:
julian 2023-05-05 10:17:20 -06:00
parent 0ca5e46474
commit 0ab96ad6a1
2 changed files with 34 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -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(),