getWithIntercept function

Future getWithIntercept(
  1. String endpoint, {
  2. Map<String, String>? headers,
  3. Duration timeoutDuration = const Duration(seconds: 60),
})

Implementation

Future<dynamic> getWithIntercept(String endpoint,
    {Map<String, String>? headers,
    Duration timeoutDuration = const Duration(seconds: 60)}) async {
  await initBinoxusPayEnvs();

  final baseUrl = binoxusPayEnvSingleton.baseUrl;
  final url = Uri.parse("$baseUrl$endpoint");
  // debugPrint('formated get url : $url');
  try {
    final response = await httpClient.get(url, headers: headers);
    // debugPrint('response  : ${response.body}');
    if (response.statusCode == 200 || response.statusCode == 201) {
      return jsonDecode(response.body);
    } else {
      throw Exception('Error : ${response.statusCode}');
    }
  } on HttpException catch (e) {
    throw Exception('Request failed: ${e.message}');
  }
}