makeRequest method
API request Method
Implementation
@mustCallSuper
Future<dynamic> makeRequest(
String endUrl,
String method, {
dynamic body,
String? contentType,
Decoder? decoder,
Map<String, String>? headers,
Map<String, dynamic>? query,
Progress? uploadProgress,
}) async {
_debugLog('makeRequest called - Method: $method, URL: $endUrl');
_debugLog('Headers: ${headers ?? _headers}');
_debugLog('Query: $query');
_debugLog('Body: $body');
final connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult.length == 1 &&
connectivityResult.contains(ConnectivityResult.none)) {
_debugLog('No internet connection detected', isError: true);
ApiError apiError = _handleInternetError();
String errorMsg =
"Error: ${apiError.message}, StatusCode : ${apiError.statusCode}";
_showSnackBar ? Get.snackbar("Error", errorMsg) : "";
return _handleInternetError();
}
try {
headers ?? _headers;
_debugLog('Sending request to: $_baseUrl$endUrl');
final response = await request(
endUrl,
method,
headers: headers,
body: body,
contentType: contentType,
decoder: decoder,
query: query,
uploadProgress: uploadProgress,
);
_debugLog('Response received - Status: ${response.statusCode}');
return processAndHandleResponse(response);
} on GetHttpException catch (ex) {
_debugLog('GetHttpException: ${ex.message}', isError: true);
return throwErrorMakeRequest(ex);
} on UnauthorizedException catch (ex) {
_debugLog('UnauthorizedException: $ex', isError: true);
return throwErrorMakeRequest(ex);
} on UnexpectedFormat catch (ex) {
_debugLog('UnexpectedFormat: ${ex.message}', isError: true);
return throwErrorMakeRequest(ex);
} on Exception catch (ex) {
_debugLog('Exception: $ex', isError: true);
return throwErrorMakeRequest(ex);
} on FlutterErrorDetails catch (ex) {
_debugLog('FlutterErrorDetails: ${ex.exceptionAsString()}',
isError: true);
return throwErrorMakeRequest(ex);
}
}