PurchaseError.fromPlatformError constructor

PurchaseError.fromPlatformError(
  1. Map<String, dynamic> errorData,
  2. IapPlatform platform
)

Creates a PurchaseError from platform-specific error data

Implementation

factory PurchaseError.fromPlatformError(
  Map<String, dynamic> errorData,
  IapPlatform platform,
) {
  ErrorCode errorCode = errorData['code'] != null
      ? ErrorCodeUtils.fromPlatformCode(errorData['code'], platform)
      : ErrorCode.Unknown;

  // Always try to infer from message if we have one, as it might provide more specific information
  if (errorData['message'] != null) {
    final inferredCode = _normalizeToErrorCode(errorData);
    if (inferredCode != ErrorCode.Unknown) {
      errorCode = inferredCode;
    }
  }

  return PurchaseError(
    message: errorData['message']?.toString() ?? 'Unknown error occurred',
    responseCode: errorData['responseCode'] as int?,
    debugMessage: errorData['debugMessage']?.toString(),
    code: errorCode,
    productId: errorData['productId']?.toString(),
    platform: platform,
  );
}