sendRaw method

Future<StreamedResponse> sendRaw({
  1. required String method,
  2. required String requestUri,
  3. required Map<String, AwsExceptionFn> exceptionFnMap,
  4. bool signed = true,
  5. Map<String, List<String>>? queryParams,
  6. Map<String, String>? headers,
  7. dynamic payload,
  8. String? resultWrapper,
})

Implementation

Future<StreamedResponse> sendRaw({
  required String method,
  required String requestUri,
  required Map<String, AwsExceptionFn> exceptionFnMap,
  bool signed = true,
  Map<String, List<String>>? queryParams,
  Map<String, String>? headers,
  dynamic payload,
  String? resultWrapper,
}) async {
  final rq = await _buildRequest(
    method,
    requestUri,
    signed,
    queryParams,
    payload,
    headers,
  );
  final rs = await _client.send(rq);

  if (rs.statusCode < 200 || rs.statusCode >= 300) {
    final body = await rs.stream.bytesToString();
    XmlDocument? root;
    if (body.isNotEmpty == true) {
      root = XmlDocument.parse(body);
    }
    final elem = root?.rootElement;

    if (elem?.name.local == 'ErrorResponse') {
      final error = elem!.findElements('Error').first;
      final type = error.findElements('Type').first.innerText;
      final code = error.findElements('Code').first.innerText;
      final message = error.findElements('Message').first.innerText;
      final fn = exceptionFnMap[code];
      final exception = fn != null
          ? fn(type, message)
          : GenericAwsException(type: type, code: code, message: message);
      throw exception;
    } else if (elem?.name.local == 'Error') {
      final code = elem!.findElements('Code').first.innerText;
      final message = elem.findElements('Message').first.innerText;
      throw GenericAwsException(code: code, message: message);
    } else {
      throwException(rs, body, exceptionFnMap);
    }
  }
  return rs;
}