class CosmosTransactionScopeError
extends Error
Since 0.2.0

Thrown when a Cosmos transaction is asked to do something a transactional batch cannot express.

Cosmos offers atomicity only as a batch that is scoped to ONE container and ONE partition-key value, and capped at 100 operations (measured: a second partition-key value answers 400, and the 101st operation is refused by the SDK). A Unit of Work that crosses one of those bounds is refused at the write that crosses it, rather than at commit, so the caller learns which write broke the scope instead of merely that the batch did.

Examples

Example 1

try {
  await db.transaction(async (uow) => {
    await uow.getRepository('Order').create({ id: 'o1', tenantId: 't1' });
    await uow.getRepository('Order').create({ id: 'o2', tenantId: 't2' });
  });
} catch (err) {
  if (err instanceof CosmosTransactionScopeError) {
    console.error(err.message);
  }
}

Constructors

CosmosTransactionScopeError(message: string)

Creates the error.

Parameters
message: string

The full diagnostic, safe to log

Properties

readonly
name: string

Discriminant for consumers that cannot use instanceof across realms.

Usage

import { CosmosTransactionScopeError } from "database-plugin/src/index.ts";