RestError

View as MarkdownOpen in Claude

Custom error class for REST API errors. Extends JavaScript’s built-in Error class. Thrown when an HTTP request to the SignalWire REST API returns a non-success status code. The name property is always "RestError".

1import { RestError } from '@signalwire/sdk';

Properties

statusCode
number

HTTP status code returned by the API (e.g., 404, 422, 500).

body
string

Raw response body from the API.

url
string

The URL that was requested.

method
string

The HTTP method used ("GET", "POST", "PUT", "PATCH", "DELETE").

name
string

Always "RestError".

message
string

Human-readable summary: "{method} {url} returned {statusCode}: {body}".

Example

1import { RestClient, RestError } from "@signalwire/sdk";
2
3const client = new RestClient({
4 project: "your-project-id",
5 token: "your-api-token",
6 host: "your-space.signalwire.com"
7});
8
9try {
10 await client.phoneNumbers.get("nonexistent-id");
11} catch (e) {
12 if (e instanceof RestError) {
13 console.log(`HTTP ${e.statusCode}: ${e.body}`);
14 console.log(`Request: ${e.method} ${e.url}`);
15 }
16}