The JavaScript SDK is in pre-release and not on npm yet. Install it from source.
FolkwaysDocs

Errors and troubleshooting

Handle RealtimeError, know which errors the SDK retries for you, and fix the most common setup problems.

Every failure the SDK reports is a RealtimeError, whether it came from the node or was caught locally before anything was sent.

import { Code, isRealtimeError } from '@folkways/realtime';

try {
  await client.topic('chat/lobby').publish('message', { text: 'hi' });
} catch (err) {
  if (isRealtimeError(err) && err.code === Code.Forbidden) {
    showError("You can't post in this room");
  } else {
    throw err;
  }
}
FieldMeaning
codeA number from Code, e.g. Code.Forbidden (203)
codeNameThe code's name, e.g. 'Forbidden'
messageWhat went wrong, including the topic when there is one
retryWhat may help: 'never', 'backoff' (try again later), 'after-reauth' (with a new token) or 'reconnect'
retryAfterMsHow long the node asked you to wait, when it did
topicThe topic the error is about, when there is one
localtrue when the SDK raised it without asking the node, e.g. a bad topic name

The SDK already retries what can be retried: reconnects, token refreshes, rate-limited publishes and server errors. The errors you see are the ones it couldn't fix.

Where errors show up

WhereWhat
await client.connect()Fatal connection errors, or Timeout while it keeps trying
await topic.publish()That publish's failure
sub.ready and sub.on('error')The subscription was refused or failed, or your handler threw
sub.on('ended')The node ended the subscription, e.g. after permissions narrowed
client.connection.on('error')Everything else: failed token refreshes, dropped outbox entries, errors in your listeners
client.connection.errorWhy the connection is failed

Common problems

You seeUsually meansFix
AuthRequiredYour token endpoint failed or returned no tokenCheck the endpoint answers 200 with { "token": "…" } for a signed-in user
AuthInvalidThe node can't verify the tokenThe kid must be one of the segment's signing keys and match its algorithm; seg must be this segment's ID; the token must live at most 15 minutes. For a publishable key: it was revoked or expired, or anonymous connections are off
AuthExpiredThe token ran out and couldn't be refreshedUse authUrl or a token function, not a fixed string. Check your server's clock
ForbiddenThe token or the topic rule doesn't allow thisThe topic must match both the token's capabilities and a rule that allows the operation
ClassMismatchThe delivery type doesn't match the topic's rulePass delivery: 'kv' or 'signal' to match the rule's class, or publish to a topic whose rule has that class
InvalidTopicBad topic nameUse only A-Z a-z 0-9 . _ ~ : @ = + - in each level
SuspendedThe segment is turned off, the workspace's subscription ended, or the publishable key is pausedCheck the segment's Settings and the workspace's Billing
QuotaExceededA segment limit was reached: connections, topics or messagesRaise the limit in Settings or upgrade the plan
RateLimitedOver the publish rate (100 per second per connection by default)The SDK retries; slow down if it persists
PayloadTooLargeThe payload is over session.limits.maxPayloadBytesSend less, or a reference to the data
ReplacedThe same user connected from too many devices; this one was closedShow "signed in elsewhere"; reconnect only when the user asks
SegmentMismatchconnect({ segment }) got a token for another segmentCheck which environment's backend issued the token
NotConnectedThe client has been offline for over 2 minutesWait for connected, or use a persistent store to queue
TimeoutNo answer in timeFor connect(): it keeps trying in the background

Turn on logs to see what the SDK is doing (tokens are never logged):

import { consoleLogger } from '@folkways/realtime';

new Folkways.Realtime({ url, authUrl, logger: consoleLogger('debug') });

The full list of codes is in the error code reference.

On this page