Skip to content

feat(whatsapp): expose typed API errors - #896

Merged
bensabic merged 5 commits into
mainfrom
josh/whatsapp-errors
Sep 5, 2026
Merged

feat(whatsapp): expose typed API errors#896
bensabic merged 5 commits into
mainfrom
josh/whatsapp-errors

Conversation

@dancer

@dancer dancer commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

summary

  • export WhatsAppApiError so consumers can handle Meta error codes without parsing error messages
  • expose HTTP status, provider details, optional subcode and trace ID, and the raw response
  • cover message requests, media uploads, and media metadata failures while preserving existing error messages and AdapterError compatibility
  • add regression coverage and document error handling

closes #712

@dancer
dancer requested a review from a team as a code owner September 4, 2026 17:27
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
chat Ready Ready Preview, v0 Sep 5, 2026 5:49am UTC
chat-sdk-nextjs-chat Ready Ready Preview, v0 Sep 5, 2026 5:49am UTC

WhatsAppApiError now maps the HTTP status and Meta error code onto the shared AdapterError codes (RATE_LIMITED, AUTH_FAILED, PERMISSION_DENIED, NOT_FOUND) and keeps Meta's numeric code in errorCode. It also lifts Meta's message and type, accepts numeric codes serialized as strings, and keeps the error message to Meta's message or a bounded excerpt while raw retains the full body. Adds WhatsAppGraphError and WhatsAppGraphErrorBody types for the envelope.

Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
…Error

Route the metadata, upload, and JSON request paths through a single graphFetchJson helper. A rejected fetch or an unparseable body now throws NetworkError instead of leaking a raw TypeError or SyntaxError; non-2xx responses still throw WhatsAppApiError. Also exports the new Graph error types.

Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
Describe the shared code mapping, errorCode, providerMessage, and type, and state which failures throw WhatsAppApiError, NetworkError, or a plain AdapterError. Add errors.ts and the error exports to the package AGENTS.md.

Signed-off-by: Ben Sabic <bensabic@users.noreply.github.com>
@bensabic
bensabic enabled auto-merge (squash) September 5, 2026 05:49
@bensabic
bensabic merged commit 31bce0a into main Sep 5, 2026
19 checks passed
@bensabic
bensabic deleted the josh/whatsapp-errors branch September 5, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed error export from @chat-adapter/whatsapp (provider error codes reachable without structural parsing)

2 participants