RelayrtcDocs
Get started
Documentation
Node SDK

RelayApiError

Handle HTTP, transport, validation and cancellation failures.

On this page

Import and client

Set RELAYRTC_API_URL and RELAYRTC_SECRET_KEY in your backend environment. Keep the secret key on the server.

TypeScript
import { RelayApiError, RelayServer } from '@relayrtc/node'
 
const relay = new RelayServer({
  apiUrl: process.env.RELAYRTC_API_URL!,
  apiKey: process.env.RELAYRTC_SECRET_KEY!,
})

Fields

FieldMeaning
codeAPI or SDK error code.
messageHuman-readable description.
statusHTTP status or null for local/transport errors.
requestIdServer request ID when available.
retryableWhether the failure can be transient.
retryAfterMsParsed Retry-After delay in milliseconds, or null when absent or invalid.

Example

TypeScript
export async function readRoom(roomId: string) {
  try {
    return await relay.rooms.get(roomId)
  } catch (error) {
    if (error instanceof RelayApiError) {
      console.error(error.code, error.status, error.requestId)
    }
    throw error
  }
}

SDK codes

CodeMeaning
INVALID_CONFIGURATIONInvalid URL, key format or options.
INVALID_REQUESTInvalid local parameters or body serialization.
INVALID_RESPONSENon-JSON success, unexpected shape or excessive response body.
NETWORK_ERRORRequest failed before a usable response.
REQUEST_TIMEOUTRequest deadline expired.
REQUEST_CANCELLEDCaller aborted the request.
HTTP_ERRORHTTP failure without a structured API code.

API failures keep the server's code, such as API_KEY_SCOPE_REQUIRED or RESOURCE_NOT_FOUND. retryable is a hint; it does not make a write operation safe to repeat.

For rate limits, preserve the HTTP status and cooldown when responding from your application backend. GET retries wait for Retry-After when it fits the request deadline; otherwise the SDK returns the original error, including status and retryAfterMs. The field requires an SDK version containing this transport behavior.