parseResponse<T> method

BaseServiceResponse<T> parseResponse<T>(
  1. List<int> bodyBytes, [
  2. int? statusCode
])

Implementation

BaseServiceResponse<T> parseResponse<T>(
  List<int> bodyBytes, [
  int? statusCode,
]) {
  statusCode ??= 200;
  if (!ServiceProviderUtils.isSuccessStatusCode(
    statusCode,
    allowSuccessStatusCodes: successStatusCodes,
  )) {
    return ServiceErrorResponse(
      statusCode: statusCode,
      error: ServiceProviderUtils.findError(
        object: bodyBytes,
        statusCode: statusCode,
        allowStatusCode: errorStatusCodes,
      ),
    );
  }
  try {
    T response = ServiceProviderUtils.toResult<T>(bodyBytes);
    return ServiceSuccessRespose<T>(
      statusCode: statusCode,
      response: response,
    );
  } catch (_) {}

  throw RPCError(
    message: "Parsing response failed.",
    request: toJson(),
    details: {"expected": "$T"},
  );
}