Skip to content

Error Handling ​

Every failure is a WhatsAppError. There are no bare SyntaxErrors from HTML error pages, and no plain TypeError: fetch failed.

ts
import { WhatsAppError } from "@osamahalhwawi/wa-client";

try {
  await wa.sendText(to, "Hello");
} catch (err) {
  if (!(err instanceof WhatsAppError)) throw err;

  switch (err.code) {
    case 131047: // more than 24h since the user's last message
      await wa.sendTemplate(to, { name: "follow_up", language: "en" });
      break;
    case 131026: // recipient is not on WhatsApp / can't receive
      await markInvalid(to);
      break;
    default:
      console.error(err.message, err.details, err.fbtraceId);
  }
}

Properties ​

PropertyDescription
kind"api", "http", "network", "timeout" or "aborted"
statusHTTP status (0 if no response was received)
codeGraph API error code
subcodeGraph API error subcode
typeGraph API error type, e.g. OAuthException
messageerror_user_msg if Meta provided one, otherwise message
userTitleerror_user_title
detailserror_data.details, often the most useful explanation
isTransientMeta's hint that retrying may succeed
fbtraceIdInclude this when contacting Meta support
bodyRaw response body (parsed JSON, or the first 1000 characters of text)
isRateLimittrue for codes 4, 80007, 130429, 131056 or HTTP 429
causeThe underlying error for network / timeout failures

Kinds ​

KindMeaning
apiMeta returned a structured error. code is set.
httpNon-2xx without a Graph error body (e.g. a 502 HTML page), or a 200 with a non-JSON body
networkNo response: DNS failure, connection reset, ...
timeoutThe request exceeded timeoutMs
abortedYour AbortSignal fired

Common error codes ​

CodeMeaningWhat to do
0Auth exceptionToken is invalid or expired
100Invalid parameterCheck details
130429Throughput limit reachedRetried automatically
131026Message undeliverableNumber not on WhatsApp, or old app version
131047Re-engagement required (24h window closed)Send a template
131048Spam rate limit / messaging tier reachedWait (often until the next day) or raise your tier
131051Unsupported message type
131056Too many messages to the same userRetried automatically
132000Template parameter count mismatchCheck components
132001Template doesn't exist in that languageCheck name / language
133010Phone number not registeredCall registerPhoneNumber

The full list is in Meta's error code reference.

Released under the MPL-2.0 License. Not affiliated with Meta Platforms, Inc. or WhatsApp LLC.