Skip to main content

AgentReinUnavailableError

Thrown when the SDK cannot reach the AgentRein backend during authentication. If authentication succeeds but session creation fails, an AxiosError is thrown.
[!NOTE] Developers should catch both error types when using failureMode: 'closed'.
import { AgentReinUnavailableError } from 'agentrein';

try {
  const session = await agentrein.newSession({ agentId: 'my-agent' });
} catch (err) {
  if (err instanceof AgentReinUnavailableError) {
    // backend is down
  }
}
Thrown when a human rejects a requiresApproval action. AgentRein automatically triggers session rollback before throwing.
import { AgentRein, ApprovalRejectedError } from 'agentrein';

const agentStripe = agentrein.wrap(stripe, session, {
    connector: 'stripe',
    requiresApproval: ['subscriptions.cancel'],
});

try {
    await agentStripe.subscriptions.cancel({ id: 'sub_123' });
} catch (err) {
    if (err instanceof ApprovalRejectedError) {
        // err.reason — the reason string provided by the human reviewer
        // err.message — "Action rejected by reviewer: <reason>"
        console.log('Rejected:', err.reason);
        // session has already been rolled back
    }
}
Thrown when a requiresApproval action is not reviewed within the timeoutMs window. Unlike ApprovalRejectedError, no automatic rollback is triggered — you must decide whether to roll back manually.
import { AgentRein, ApprovalTimeoutError, ApprovalRejectedError } from 'agentrein';

try {
  await agentStripe.subscriptions.cancel({ id: 'sub_123' });
} catch (err) {
  if (err instanceof ApprovalTimeoutError) {
    // err.approvalId — the ID of the approval request
    // err.timeoutMs  — the timeout duration that was exceeded
    console.log(`Approval ${err.approvalId} timed out after ${err.timeoutMs}ms`);
    await agentrein.rollbackSession(session); // optional: roll back manually
  }
  if (err instanceof ApprovalRejectedError) {
    // session already rolled back automatically
  }
}
Thrown synchronously when invalid options are passed to wrap(). Common causes: pollIntervalMs below 1000ms or timeoutMs below 5000ms.
import { AgentRein, WrapOptionsValidationError } from 'agentrein';

try {
  const agentOctokit = agentrein.wrap(octokit, session, {
    connector: 'github',
    pollIntervalMs: 500,   // ❌ too low — minimum is 1000
    timeoutMs: 3000,       // ❌ too low — minimum is 5000
  });
} catch (err) {
  if (err instanceof WrapOptionsValidationError) {
    console.error('Invalid wrap options:', err.message);
  }
}
Valid minimums:
OptionMinimumDefault
pollIntervalMs10002000
timeoutMs500030000