@zyphr-dev/node-sdk 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -535,6 +535,45 @@ All error classes extend `ZyphrError`, which extends `Error`:
535
535
  | `limitBytes` | `number \| undefined` | Server-enforced body cap (`ZyphrPayloadTooLargeError` only) |
536
536
  | `receivedBytes` | `number \| undefined` | Size of the rejected body (`ZyphrPayloadTooLargeError` only) |
537
537
 
538
+ ### Branch on `error.code`, not `error.message`
539
+
540
+ `error.code` carries the API's stable, machine-readable code — branch on it
541
+ instead of matching `message` text (which is display copy and may change).
542
+ The code is the exact value from the API response body (e.g. `account_frozen`,
543
+ `account_throttled`, `otp_invalid`, `email_not_found`), not a generic
544
+ per-status placeholder:
545
+
546
+ > **Behavior change (≥ 0.1.30):** `error.code` now reflects the API's actual
547
+ > machine-readable code for every status. Previously the SDK overwrote it with a
548
+ > generic per-status placeholder (`authentication_error`, `rate_limit_exceeded`,
549
+ > `validation_error`, …). If you were matching those generic strings, switch to
550
+ > `instanceof` for the error *class* and use `error.code` for the specific
551
+ > condition. `error.status` and the error classes are unchanged.
552
+
553
+ ```ts
554
+ try {
555
+ await zyphr.emails.sendEmail({ /* ... */ });
556
+ } catch (error) {
557
+ if (error instanceof ZyphrError) {
558
+ switch (error.code) {
559
+ case 'account_frozen': // 403 — sending paused for reputation; see the dashboard
560
+ case 'account_throttled': // 429 — sending throttled; back off and retry
561
+ // ...handle the account's sending state
562
+ break;
563
+ case 'otp_invalid': // 400 — wrong/expired OTP
564
+ case 'email_not_found': // 404 — no account for this email (registration fallback)
565
+ // ...
566
+ break;
567
+ }
568
+ }
569
+ }
570
+ ```
571
+
572
+ The full catalog of codes per endpoint is at
573
+ [zyphr.dev/docs/resources/error-codes](https://zyphr.dev/docs/resources/error-codes).
574
+ Reading `error.code` also flows through the Zyphr MCP server, so agents get the
575
+ same actionable code.
576
+
538
577
  ## Bundle
539
578
 
540
579
  Dual-format build — works with both ESM and CommonJS: