***

title: RestError
slug: /reference/typescript/rest/rest-error
description: Error thrown when the REST API returns a non-success response.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

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"`.

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

## **Properties**

<ParamField path="statusCode" type="number" toc={true}>
  HTTP status code returned by the API (e.g., `404`, `422`, `500`).
</ParamField>

<ParamField path="body" type="string" toc={true}>
  Raw response body from the API.
</ParamField>

<ParamField path="url" type="string" toc={true}>
  The URL that was requested.
</ParamField>

<ParamField path="method" type="string" toc={true}>
  The HTTP method used (`"GET"`, `"POST"`, `"PUT"`, `"PATCH"`, `"DELETE"`).
</ParamField>

<ParamField path="name" type="string" toc={true}>
  Always `"RestError"`.
</ParamField>

<ParamField path="message" type="string" toc={true}>
  Human-readable summary: `"{method} {url} returned {statusCode}: {body}"`.
</ParamField>

## **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}`);
  }
}
```