Skip to content

Errors and types

Errors

RoomAdmissionError, the errors startup can throw, and how to retry.

createRoom() rejects with a RoomAdmissionError when the Ball2D service refuses a room. Other startup failures are ordinary errors: a malformed key is a TypeError, an invalid setting is an Error that names it, and a slow startup is a TimeoutError. See Errors and retries for a complete retry strategy.

Import fromball2dball2d/node

JavaScript
import { createRoom, RoomAdmissionError } from 'ball2d/node';

try {
  await createRoom(config);
} catch (error) {
  if (
    error instanceof RoomAdmissionError &&
    error.status === 429
  ) {
    await sleep((error.retryAfterSeconds ?? 60) * 1000);
  } else throw error;
}

status

property
error.status: number
readonly

The HTTP status the service returned.

StatusMeaningWhat to do
400The room settings were rejected.Fix the settings; retrying won't help.
401The API key is invalid, expired or revoked.Create a new key.
403The key may not create rooms, or the request came from a rejected origin.Check the key and serviceOrigin.
409A retried request changed its settings.Start a new createRoom() call.
410The reservation or authorization ended before the room opened.Start a new createRoom() call.
429A room limit or request budget is exhausted.Wait retryAfterSeconds, or close a running room.
503The service is temporarily unavailable.Retry with backoff.

The message carries the service's explanation when it has one, such as This API key already has an active room. (429). For 401 it is always API key is invalid, expired or revoked. Create a key from your Ball2D account., and for server errors it is Room creation failed (<status>).

retryAfterSeconds

property
error.retryAfterSeconds: number | null
readonly

Seconds to wait before trying again, from the service's Retry-After header. Set for 429 responses (currently always 60) and null otherwise.