Error Classes
Every failure is a TalonicError subclass with status, code, retryable, and requestId properties. The class hierarchy maps HTTP status codes to specific error types so you can handle each failure category independently.
import {
TalonicError, // base class — catches all SDK errors
TalonicAuthError, // 401, 403 — invalid key or insufficient permissions
TalonicNotFoundError, // 404 — resource does not exist
TalonicValidationError, // 400, 409, 413, 422 — bad input, conflict, file too large
TalonicRateLimitError, // 429 — rate limited (after retries exhausted)
TalonicServerError, // 500, 502, 503, 504 — server error (after retries exhausted)
TalonicNetworkError, // DNS / TCP failures — status: 0, code: 'network_error'
TalonicTimeoutError, // request exceeded configured timeout — status: 0, code: 'timeout'
} from '@talonic/node'Each error class maps to a specific failure category. TalonicAuthError covers authentication and permission failures (401, 403). TalonicValidationError covers request rejections like bad input, conflicts, oversized files, or unprocessable entities (400, 409, 413, 422). TalonicRateLimitError and TalonicServerError are only thrown after all retries are exhausted.
// Every TalonicError subclass carries these properties:
try {
await talonic.extract({ file_path: './doc.pdf', schema_id: 'sch_invalid' })
} catch (err) {
if (err instanceof TalonicError) {
err.code // 'invalid_schema' — machine-readable error code
err.status // 422 — HTTP status (0 for network/timeout)
err.message // 'Schema sch_invalid not found' — human-readable
err.retryable // false — was this error retried?
err.requestId // 'req_abc123' — server trace ID (undefined for transport errors)
err.name // 'TalonicValidationError' — class name
}
}TalonicNetworkError and TalonicTimeoutError represent transport-level failures that never reached the server. Both carry status: 0 and are retried automatically. The code property is set to "network_error" or "timeout" respectively, and retryable is always true. TalonicNetworkError preserves the original error as cause for debugging DNS failures, TCP resets, and unreachable hosts. TalonicTimeoutError includes a timeoutMs property with the configured timeout value that was exceeded.
import { TalonicNetworkError, TalonicTimeoutError, TalonicRateLimitError } from '@talonic/node'
try {
await talonic.extract({ file_path: './doc.pdf', schema_id: 'sch_abc123' })
} catch (err) {
if (err instanceof TalonicTimeoutError) {
console.error(`Request timed out after ${err.timeoutMs}ms`)
// err.status === 0, err.code === 'timeout', err.retryable === true
}
if (err instanceof TalonicNetworkError) {
console.error(`Network failure: ${err.message}`)
console.error(`Original error: ${err.cause}`) // underlying DNS/TCP error
// err.status === 0, err.code === 'network_error', err.retryable === true
}
if (err instanceof TalonicRateLimitError) {
console.error(`Rate limited. Limit: ${err.rateLimit.limit}, remaining: ${err.rateLimit.remaining}`)
console.error(`Resets at: ${err.rateLimit.resetAt.toISOString()}`)
// err.rateLimit provides { limit, remaining, resetAt } from response headers
}
}All error classes extend the base TalonicError, so a single catch with instanceof TalonicError captures every SDK failure. Use more specific subclasses when you need to branch on failure mode, such as showing a different message for auth errors versus validation errors. The TalonicRateLimitError is unique in carrying a rateLimit property with limit, remaining, and resetAt (Date) from the response headers, useful for scheduling manual retries after the SDK's own retries are exhausted.
The SDK also throws client-side TalonicError instances (not subclasses) for parameter validation failures before any network request is made. These carry status: 0, retryable: false, and codes like missing_file_source, multiple_file_sources, multiple_schemas, or missing_field_reference. They indicate programming errors in how the SDK is called rather than server-side failures.
requestId property (when available) that maps to the server-side request log. Include it in support tickets for fast debugging.