REST Client

SignalWireRestError

View as MarkdownOpen in Claude

Custom exception class for REST API errors. Extends Python’s built-in Exception class. Raised when an HTTP request to the SignalWire REST API returns a non-success status code.

from signalwire.rest import SignalWireRestError

A request that never produces a response raises SignalWireRestTransportError, a subclass of this class. Catching SignalWireRestError handles both.

Properties

status_code
int | NoneDefaults to None

HTTP status code returned by the API (e.g., 404, 422, 500). None for a transport failure that produced no response.

body
str | dict

Response body from the API (JSON dict if parseable, otherwise raw string).

url
str

The full URL that was requested, including the query string.

method
str

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

headers
dict[str, str] | NoneDefaults to None

Response headers from the API. None for a transport failure.

request_id
str | NoneDefaults to None

The platform request ID, read from the x-request-id, x-signalwire-request-id, request-id, or x-amzn-requestid response header. Also appended to the exception message. Quote it when contacting support.

Example

from signalwire.rest import RestClient, SignalWireRestError
client = RestClient(
project="your-project-id",
token="your-api-token",
host="your-space.signalwire.com",
)
try:
client.phone_numbers.get("nonexistent-id")
except SignalWireRestError as e:
print(f"HTTP {e.status_code}: {e.body}")
print(f"Request: {e.method} {e.url}")
print(f"Request ID: {e.request_id}")