getWithDio function

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

Implementation

FutureOr<dynamic> getWithDio(String endpoint,
    {Map<String, String>? headers,
    Duration timeoutDuration = const Duration(seconds: 60)}) async {
  final dio = _configureDio(timeoutDuration: timeoutDuration);
  await initBinoxusPayEnvs();
  final baseUrl = binoxusPayEnvSingleton.baseUrl;
  final url = "$baseUrl$endpoint";

  try {
    final response = await dio.get(url, options: Options(headers: headers));

    if (response.statusCode! >= 200 && response.statusCode! <= 201) {
      return response.data;
    } else {
      throw Exception('Error : ${response.statusCode}');
    }
  } on DioException catch (e) {
    if (e.type == DioExceptionType.connectionTimeout ||
        e.type == DioExceptionType.receiveTimeout) {
      throw Exception('Request to $endpoint timed out');
    } else {
      throw Exception('Request failed: ${e.message}');
    }
  }
}