call method

  1. @override
Future<Response> call(
  1. HttpMethod method, {
  2. String path = '',
  3. Map<String, String> headers = const {},
  4. Map<String, dynamic> params = const {},
  5. ResponseType? responseType,
})

Implementation

@override
Future<Response> call(
  HttpMethod method, {
  String path = '',
  Map<String, String> headers = const {},
  Map<String, dynamic> params = const {},
  ResponseType? responseType,
}) async {
  while (!_initialized && _initProgress) {
    await Future.delayed(Duration(milliseconds: 10));
  }
  if (!_initialized) {
    await init();
  }

  late http.Response res;
  http.BaseRequest request = prepareRequest(
    method,
    uri: Uri.parse(_endPoint + path),
    headers: {..._headers!, ...headers},
    params: params,
  );

  try {
    request = await _interceptRequest(request);
    final streamedResponse = await _httpClient.send(request);
    res = await toResponse(streamedResponse);
    res = await _interceptResponse(res);

    return prepareResponse(
      res,
      responseType: responseType,
    );
  } catch (e) {
    if (e is AppwriteException) {
      rethrow;
    }
    throw AppwriteException(e.toString());
  }
}