getRequest method

Future getRequest(
  1. String endUrl, {
  2. Map<String, String>? headers,
  3. String? contentType,
  4. Map<String, dynamic>? query,
  5. Decoder? decoder,
})

API Get Method

Implementation

Future<dynamic> getRequest(String endUrl,
    {Map<String, String>? headers,
    String? contentType,
    Map<String, dynamic>? query,
    Decoder? decoder}) async {
  _debugLog('GET Request - URL: $endUrl');
  _debugLog('Query Parameters: $query');

  final connectivityResult = await (Connectivity().checkConnectivity());
  if (connectivityResult.length <= 1 &&
      connectivityResult.first == ConnectivityResult.none) {
    _debugLog('No internet connection detected', isError: true);
    throw _handleInternetError();
  }
  try {
    headers ?? _headers;
    decoder ?? _defaultDecoder;
    _debugLog('Sending GET request to: $_baseUrl$endUrl');
    final response = await get(endUrl,
        query: query,
        contentType: contentType,
        headers: headers,
        decoder: decoder);
    _debugLog('GET Response - Status: ${response.statusCode}');
    return processAndHandleResponse(response);
  } on GetHttpException catch (ex) {
    _debugLog('GET GetHttpException: ${ex.message}', isError: true);
    throw _handleError(ex);
  } on UnauthorizedException catch (ex) {
    _debugLog('GET UnauthorizedException: $ex', isError: true);
    throw _handleError(ex);
  } on UnexpectedFormat catch (ex) {
    _debugLog('GET UnexpectedFormat: ${ex.message}', isError: true);
    throw _handleError(ex);
  } on Exception catch (ex) {
    _debugLog('GET Exception: $ex', isError: true);
    throw _handleError(ex);
  } on FlutterErrorDetails catch (ex) {
    _debugLog('GET FlutterErrorDetails: ${ex.exceptionAsString()}',
        isError: true);
    throw _handleError(ex);
  }
}