> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # RestError > Error thrown when the REST API returns a non-success response. 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. ```typescript {1} 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 | 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`. ```typescript {1} import { RestTransportError } from "@signalwire/sdk"; ``` ## **Example** ```typescript {9} 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}`); } } ``` > Error thrown when the REST API returns a non-success response.