Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error Handling

HTTP

The API returns standard HTTP status codes:

StatusMeaning
200Success
400Bad request (invalid parameters)
401Unauthorized (wrong or missing auth token)
404Not found (stream_id expired or unknown)
409Conflict (operation already in progress)
500Internal server error

Error responses include a JSON body:

{ "error": "Invalid or unsupported version." }

For async operations, terminal error events arrive in the polling stream:

curl -s "$BASE_URL/events/$STREAM?after=0" -H "Authorization: Bearer $AUTH_TOKEN"
# → { "events": [{ "data": { "status": "error", "reason": "user_rejected" } }] }
JavaScript

The SDK throws PortalSDKError with a code property:

import { PortalSDKError } from 'portal-sdk';

try {
  await client.connect();
  await client.authenticate(token);
} catch (err) {
  if (err instanceof PortalSDKError) {
    // err.code: AUTH_FAILED, CONNECTION_TIMEOUT, CONNECTION_CLOSED, NOT_CONNECTED, etc.
  }
  throw err;
}

Error codes

CodeWhen
NOT_CONNECTEDMethod called before connect() or after disconnect.
CONNECTION_TIMEOUTConnection did not open within connectTimeout.
CONNECTION_CLOSEDSocket closed unexpectedly.
AUTH_FAILEDInvalid or rejected auth token.
UNEXPECTED_RESPONSEServer sent unexpected response type.
SERVER_ERRORServer returned an error (err.message).
PARSE_ERRORFailed to parse a message; optional err.details.
Java

Check the err parameter in each sendCommand callback; handle connection and auth failures before sending commands.

sdk.sendCommand(someRequest, (response, err) -> {
    if (err != null) {
        System.err.println("Command failed: " + err);
        return;
    }
    // use response
});

Next: Authentication Guide