genericHttpGet method

Future<Response> genericHttpGet(
  1. String url,
  2. Map<String, String> headers
)

Implementation

Future<Response> genericHttpGet(String url, Map<String, String> headers) async {
  try{

    if(!await _beaNetworkManager.checkNetworkConnection()){
      throw new BeaInternetException("No internet connection");
    }

    var dio = Dio();
    dio.options
      ..connectTimeout = 60000 //60 sec
      ..receiveTimeout = 60000 //60 sec
      ..validateStatus = (int status) {
        return status > 0;
      }
      ..headers = headers;

    dio.interceptors
      ..add(InterceptorsWrapper(
          onError: (DioError e, handler){
            switch(e.type){
              case DioErrorType.connectTimeout:
              case DioErrorType.receiveTimeout:
              case DioErrorType.sendTimeout:
                throw new Exception("Request in timeout - ${e.message}");
                break;
              case DioErrorType.response:
                break;
              case DioErrorType.cancel:
                throw new Exception("Request cancelled - ${e.message}");
                break;
              case DioErrorType.other:
                throw new Exception("Default error - ${e.message}");
                break;
            }
          }
      ));

    Response<Map<String, dynamic>> response = await dio.get<Map<String, dynamic>>(url);

    return response;

  } on Exception catch (e){
    print('Generic HTTP GET request error');
    FLog.error(
        className: this.runtimeType.toString(),
        methodName: "genericHttpGet",
        text: 'Generic HTTP Get request error - $e');
    throw e;
  }
}