Skip to content

Error Handling

The SDK provides two typed error classes for distinct failure modes, plus a built-in error code lookup table covering all known Convoso API error codes.

Error Class Hierarchy

Error
└── ConvosoError
    ├── ConvosoApiError    — API returned success: false
    └── ConvosoHttpError   — Non-2xx HTTP status

All error classes are exported from the package:

typescript
import { ConvosoError, ConvosoApiError, ConvosoHttpError } from 'convoso-js';

ConvosoApiError

Thrown when the API returns HTTP 200 but the response body contains success: false. This is how Convoso signals business logic errors (invalid IDs, missing fields, duplicates, etc.).

PropertyTypeDescription
messagestringError message from the API
codenumberNumeric error code
bodyunknownFull response body
descriptionstring | undefinedHuman-readable description from the error code table
typescript
import { ConvosoApiError } from 'convoso-js';

try {
  await client.leads.insert({
    list_id: '999',
    phone_number: '5551234567',
  });
} catch (err) {
  if (err instanceof ConvosoApiError) {
    console.error(`Code: ${err.code}`);           // e.g. 6002
    console.error(`Message: ${err.message}`);      // e.g. "No such list"
    console.error(`Description: ${err.description}`); // e.g. "No such list"
    console.error(`Body:`, err.body);              // Full API response
  }
}

The .description Getter

ConvosoApiError includes a .description getter that looks up the error code in the SDK's built-in table. This is useful because API error messages can sometimes be cryptic or inconsistent:

typescript
catch (err) {
  if (err instanceof ConvosoApiError) {
    // .description returns undefined for unknown codes
    const msg = err.description ?? err.message;
    console.error(`Failed: ${msg} (code ${err.code})`);
  }
}

ConvosoHttpError

Thrown when the server returns a non-2xx HTTP status code (network errors, server outages, etc.).

PropertyTypeDescription
messagestring"HTTP {status}: {statusText}"
statusnumberHTTP status code
statusTextstringHTTP status text
bodystringRaw response body text
typescript
import { ConvosoHttpError } from 'convoso-js';

try {
  await client.leads.search({ list_id: '333' });
} catch (err) {
  if (err instanceof ConvosoHttpError) {
    console.error(`HTTP ${err.status}: ${err.statusText}`);
    console.error(`Response: ${err.body}`);
  }
}

Catching Both Error Types

Use instanceof checks to handle each error type differently:

typescript
import { ConvosoApiError, ConvosoHttpError } from 'convoso-js';

try {
  await client.leads.insert({ list_id: '333', phone_number: '5551234567' });
} catch (err) {
  if (err instanceof ConvosoApiError) {
    // Business logic error (bad input, not found, duplicate, etc.)
    console.error(`API Error ${err.code}: ${err.description ?? err.message}`);
  } else if (err instanceof ConvosoHttpError) {
    // Infrastructure error (server down, rate limited, etc.)
    console.error(`HTTP ${err.status}: ${err.statusText}`);
  } else {
    // Network error, DNS failure, etc.
    throw err;
  }
}

Error Code Table

All known Convoso API error codes with their descriptions. The SDK includes these as CONVOSO_ERROR_CODES and uses them to power ConvosoApiError.description.

typescript
import { CONVOSO_ERROR_CODES } from 'convoso-js';
CodeDescription
4001Missing required field
4002Field must be numeric
6000Invalid phone number
6001Record not found
6002No such list
6003Missing required name
6004Unknown or invalid ID
6005Missing required user(s)
6006Invalid user or phone
6007Missing required field or duplicate entry
6008Invalid or duplicate phone number
6009Phone number already exists
6012User is not logged in
6023Required fields are missing
6026Invalid campaign ID or country code
6031Invalid date format
6032Missing call log ID
6033No such call log
6036Either revenue or return must have a value
6041Invalid queue ID
6042Invalid list ID
6046List name too short (min 10 characters)
6050Invalid status
6056Missing or invalid ID value
6057Invalid reason provided
6058Invalid purpose provided
6059Combination already exists or update failed
6060Invalid or missing call log / status ID
6061Not found or invalid abbreviation
6062Invalid final option or extra field validation error
6063Missing or invalid reached option
6064Missing or invalid success option
6065Missing or invalid DNC option
6066Missing or invalid callback option
6067Missing or invalid contact option
6068Missing or invalid voicemail option
6069Only custom statuses can be modified
6070Invalid lead or callback ID
6071Record not found or option cannot be empty
6072Invalid timezone or option cannot be empty
6073Invalid callback ID or option cannot be empty
6074Callback not found or option cannot be empty
6075Callback option cannot be empty
6076Contact option cannot be empty
6077Voicemail option cannot be empty
6078Invalid HEX color (do not include #)
6079Invalid email address
6080Invalid status value or missing purpose field
6081List name must be unique
6090Invalid criteria key
7231Invalid offset value
7258Invalid limit value

TIP

Some error codes are context-dependent. For example, 6004 may mean "Unknown Campaign ID" or "Invalid phone number format" depending on the endpoint. The descriptions above reflect the most common interpretation.

Community project — not affiliated with or endorsed by Convoso.