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
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
error.status: numberThe HTTP status the service returned.
| Status | Meaning | What to do |
|---|---|---|
400 | The room settings were rejected. | Fix the settings; retrying won't help. |
401 | The API key is invalid, expired or revoked. | Create a new key. |
403 | The key may not create rooms, or the request came from a rejected origin. | Check the key and serviceOrigin. |
409 | A retried request changed its settings. | Start a new createRoom() call. |
410 | The reservation or authorization ended before the room opened. | Start a new createRoom() call. |
429 | A room limit or request budget is exhausted. | Wait retryAfterSeconds, or close a running room. |
503 | The 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
error.retryAfterSeconds: number | nullSeconds to wait before trying again, from the service's Retry-After header. Set for 429 responses (currently always 60) and null otherwise.