All Ocp* classes extend OcpError, which carries a string code from OcpErrorCodes, optional cause, classification, and context. Catch instanceof OcpError for unified handling, then narrow to subclasses for field paths, contract metadata, HTTP hints, or parse sources.
Hierarchy
| Class | When thrown | Notable fields |
|---|---|---|
OcpValidationError | Input fails before ledger (batch, network, payload shapes) | fieldPath, expectedType, receivedValue; default code REQUIRED_FIELD_MISSING unless overridden |
OcpContractError | DAML/ledger contract operations, missing CreatedTreeEvent, diagnosed read failures | contractId, templateId, choice; default CHOICE_FAILED |
OcpNetworkError | Connectivity / HTTP failures | endpoint, statusCode; default CONNECTION_FAILED |
OcpParseError | Schema / enum / transform mismatches | source; default INVALID_RESPONSE |
OcpErrorCodes (subset)
REQUIRED_FIELD_MISSING, INVALID_TYPE, INVALID_FORMAT, OUT_OF_RANGE, CONTRACT_NOT_FOUND, CHOICE_FAILED, AUTHORIZATION_FAILED, RESULT_NOT_FOUND, CONNECTION_FAILED, TIMEOUT, RATE_LIMITED, INVALID_RESPONSE, SCHEMA_MISMATCH, UNKNOWN_ENUM_VALUE, UNKNOWN_ENTITY_TYPE.
Examples
import { OcpError, OcpValidationError, OcpContractError } from '@open-captable-protocol/canton';
try {
await ocp.OpenCapTableReports.companyValuationReport.create(params);
} catch (e) {
if (e instanceof OcpValidationError) {
console.error(e.fieldPath, e.receivedValue);
} else if (e instanceof OcpContractError) {
console.error(e.choice, e.contractId, e.code);
} else if (e instanceof OcpError) {
console.error(e.code, e.context);
}
}
Related non-OcpError types
WaitAbortedError,WaitTimeoutError—CouponMinter.waitUntilCanMint/mintWithRateLimit(Errorsubclasses).toContractId/toPartyId/toOcfId/toSecurityId— throw plainErrorwhen empty/invalid (see branded types).