Error handling
Goal: handle failures the way the API is designed to be handled — by code, not by string-
matching a message or trusting the HTTP status alone (several codes share a status, e.g. every
409 is a state conflict but they mean different things).
Branch on code
Section titled “Branch on code”const res = await fetch(url, { headers, method: 'POST', body });if (!res.ok) { const { error } = await res.json(); switch (error.code) { case 'insufficient_balance': // show the shortfall, offer a cheaper option break; case 'tier_gated': // the member needs to reach a higher tier first break; case 'idempotency_key_reuse': case 'idempotency_key_conflict': // your retry logic has a bug — the same key was sent for two different requests break; default: // log error.code + error.request_id; don't assume you know what happened console.error(error.code, error.request_id, error.message); }}With the SDK, catch by class, not by string-comparing code yourself:
import { InsufficientBalanceError, TierGatedError, TesseraError } from '@tesseraloyalty/sdk';
try { await member.redeem({ requestedPoints, cart });} catch (err) { if (err instanceof InsufficientBalanceError) { console.log('short by', err.shortfall); } else if (err instanceof TierGatedError) { // … } else if (err instanceof TesseraError) { console.log(err.code, err.status, err.requestId); }}A code this SDK version doesn’t recognize yet resolves to the base TesseraError rather than
crashing — new codes are additive (see Changelog & versioning), so don’t treat an
unrecognized code as fatal; log it and fall through to generic handling.
Retry safely
Section titled “Retry safely”- Redemptions — always send an
Idempotency-Key; retry the exact same request with the same key and you get the original hold back, never a duplicate. - Events — the body’s
idempotency_keyis your dedup key; retrying the identical event body is a safe no-op ("status": "duplicate"). - Network errors,
5xx,429are generally safe to retry with backoff — the SDK does this automatically (maxRetries, default 2, honoringRetry-Afteron a429). A request timeout is not automatically retried — it means the call already blew its time budget. A503redemption_unavailablefromcheckoutRedemptions.placeis not retried either: its key is spent, so retry with a new one.
See Idempotency for exactly which key governs which endpoint.
Use request_id for support
Section titled “Use request_id for support”Every response — success or error — carries an X-Request-Id header, and every error envelope
echoes it as error.request_id. Log it alongside the failure; it’s the fastest way for Tessera
support to find the exact request server-side.
See Errors & the envelope for the full code → HTTP status table.