Skip to navigation

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, or when the request never reaches the server. The name property is "RestError", or "RestTransportError" for the transport subclass below.

Also exported as SignalWireRestError to match the Python SDK class name.

import { RestError } from "@signalwire/sdk";

Properties

statusCode
number | null

HTTP status code returned by the API (e.g., 404, 422, 500). null for a RestTransportError, where no response was received.

body
string | SignalWireErrorBody

Response body from the API. A SignalWireErrorBody object (code, message, and optional more_info and status) when the response was valid JSON; otherwise the raw text. For a RestTransportError, the underlying transport error message.

url
string

The URL that was requested.

method
string

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

headers
Record<string, string> | null

Response headers from the failed request. null for a transport failure.

requestId
string | null

The platform request ID read from the response headers, or null when absent. Quote it when you contact support about a failed request.

name
string

"RestError", or "RestTransportError" for a transport failure.

message
string

Human-readable summary: "{method} {url} returned {statusCode}: {body}" for an HTTP error, or "{method} {url} failed to reach the server: {body}" for a transport failure. Followed by (request-id: ...) when a request ID is available.

RestTransportError

Thrown when a request never reaches a response: a connection refused, a DNS failure, a TLS error, or a RequestOptions timeout. It extends RestError, so one catch (e instanceof RestError) handles HTTP errors and transport failures alike. statusCode, headers, and requestId are null, and body holds the underlying transport error message.

Also exported as SignalWireRestTransportError.

import { RestTransportError } from "@signalwire/sdk";

Example

import { RestClient, RestError } from "@signalwire/sdk";
const client = new RestClient({
project: "your-project-id",
token: "your-api-token",
host: "your-space.signalwire.com"
});
try {
await client.phoneNumbers.get("nonexistent-id");
} catch (e) {
if (e instanceof RestError) {
console.log(`HTTP ${e.statusCode}: ${e.body}`);
console.log(`Request: ${e.method} ${e.url}`);
console.log(`Request ID: ${e.requestId}`);
}
}