authProxyRequest<TBodyType, TResponseType> method

Future<TResponseType> authProxyRequest<TBodyType, TResponseType>(
  1. String url,
  2. TBodyType body,
  3. TResponseType fromJson(
    1. Map<String, dynamic>
    )
)

Implementation

Future<TResponseType> authProxyRequest<TBodyType, TResponseType>(
  String url,
  TBodyType body,
  TResponseType Function(Map<String, dynamic>) fromJson,
) async {
  if (config.authProxyConfigId == null || config.authProxyConfigId!.isEmpty) {
    throw Exception(
        'Missing Auth Proxy config ID. Please verify environment variables.');
  }
  final fullUrl = '${config.authProxyBaseUrl}$url';
  final stringifiedBody = jsonEncode(body);

  final response = await transport.post(
    url: fullUrl,
    body: stringifiedBody,
    headers: {
      "X-Auth-Proxy-Config-ID": config.authProxyConfigId!,
      'X-Client-Version': VERSION,
    },
  );

  if (response.statusCode != 200) {
    throw ZeroXKeyRequestError(
      GrpcStatus.fromJson(jsonDecode(response.body)),
    );
  }

  final decodedJson = jsonDecode(response.body) as Map<String, dynamic>;
  return fromJson(decodedJson);
}