fix: improve error handling and messaging in DFX Buy and OpenCryptoPay services (#2509)

* fix: improve error handling and messaging in DFX Buy and OpenCryptoPay services

* fix: adjust error handling in DFX Buy provider by updating `_getErrorMessage` function parameters and removing unused imports
This commit is contained in:
Konstantin Ullrich
2025-09-08 18:22:34 +03:00
committed by GitHub
parent 68a5821ad7
commit bac14e2d25
3 changed files with 16 additions and 8 deletions
+1 -2
View File
@@ -4,8 +4,7 @@ class OpenCryptoPayException implements Exception {
OpenCryptoPayException([this.message = '']);
@override
String toString() =>
'OpenCryptoPayException${message.isNotEmpty ? ': $message' : ''}';
String toString() => message.isNotEmpty ? message : 'OpenCryptoPayException';
}
class OpenCryptoPayNotSupportedException extends OpenCryptoPayException {
@@ -35,14 +35,12 @@ class OpenCryptoPayService {
final response =
await ProxyWrapper().get(clearnetUri: Uri.https(uri.authority, uri.path, queryParams));
final body = jsonDecode(response.body) as Map;
if (response.statusCode == 200) {
final body = jsonDecode(response.body) as Map;
if (body.keys.contains("txId")) return body["txId"] as String;
throw OpenCryptoPayException(body.toString());
}
throw OpenCryptoPayException(
"Unexpected status code ${response.statusCode} ${response.body}");
throw OpenCryptoPayException("${response.statusCode}: ${body["message"]}");
}
Future<void> cancelOpenCryptoPayRequest(OpenCryptoPayRequest request) async {