What it does
Shows the canonical error-handling shape for SDK callers:
SdkError— programming bug (e.g. calling a non-v3 method viaactions.v3.*).AjaxError— REST returned an error (ERROR_NOT_FOUND,INVALID_CREDENTIALS,EXPIRED_TOKEN,QUERY_LIMIT_EXCEEDED, …).- Network-level —
NETWORK_ERROR/REQUEST_TIMEOUT. Critically different for non-idempotent calls. - Soft errors — codes you've explicitly opted into surfacing via
softErrorCodesso the call returnsisSuccess: falseinstead of throwing.
Also covers setRestrictionManagerParams with the new knobs:
hardErrorCodes— extend the SDK's "throw immediately, no retry" list with app-specific codes.softErrorCodes— extend the "return as soft error in AjaxResult" list.retryOnNetworkError: false— disable network retry for*.add/*.update/ file uploads to avoid duplicates.
Stack
Node.js 18+. No external dependencies.
Environment
export B24_HOOK='https://your.bitrix24.com/rest/1/secret'
Run
npx tsx 10-error-handling.ts
Source
skills/b24jssdk-recipes/examples/10-error-handling.ts.
Notes
setRestrictionManagerParamsupdates the policy for all HTTP clients on this$b24instance (both v2 and v3).hardErrorCodesandsoftErrorCodesare additive — built-in lists (auth/fatal codes) are always hard. You can extend, you can't remove.- For non-idempotent calls, prefer wrapping each call in a
try/finallythat restoresretryOnNetworkError: trueafterwards. The recipe shows this pattern. - When a network timeout happens for a non-idempotent call, the safe action is reconcile (query for the just-created entity by a client-side idempotency tag), not retry.