call method

Executes the HTTP request and returns an ApiResponse.

Never throws — all errors are captured and returned in the response.

Implementation

Future<ApiResponse> call() async {
  try {
    if (enableLoading) EasyLoading.show(status: loadingMessage);
    final response = await _executeWithRetry(attempt: 0);
    if (enableLoading) await EasyLoading.dismiss();
    _handleFeedback(response);
    onComplete?.call();
    return response;
  } catch (e, stack) {
    if (enableLoading) await EasyLoading.dismiss();
    dev.log('FlutterApiCraft error: $e', stackTrace: stack, name: 'flutter_api_craft');
    final errResponse = ApiResponse(
      statusCode: 0,
      rawBody: '',
      data: null,
      isSuccess: false,
      headers: {},
      errorMessage: e.toString(),
      exception: e,
    );
    onError?.call(errResponse);
    onComplete?.call();
    return errResponse;
  }
}