Timeout & Abort
Set a global timeout for all requests, pass an AbortSignal for manual cancellation, or combine both. Timeouts and aborts throw a DOMException with name: 'AbortError', not RpcError.
Client Timeout
// Global timeout for all requests (ms)
const rpc = createRpcClient({
baseUrl: '/api',
timeout: 10000, // 10 seconds
});Per-Call Timeout
// Override timeout for a single call
const report = await rpc.query('heavy_report', input, {
timeout: 30000, // 30 seconds for this call only
});AbortSignal
A client-level signal aborts all in-flight requests when fired.
// Client-level signal — aborts all in-flight requests
const controller = new AbortController();
const rpc = createRpcClient({
baseUrl: '/api',
signal: controller.signal,
});
// Cancel everything
controller.abort();Per-Call Signal
// Per-call signal — cancel a single request
const controller = new AbortController();
const result = rpc.query('slow_query', input, {
signal: controller.signal,
});
// Cancel just this request
controller.abort();Combined Signals
When both client and per-call signals are provided, they are combined — the request aborts when either signal fires.
// Client signal + per-call signal are combined.
// The request aborts when either signal fires.
const clientCtrl = new AbortController();
const callCtrl = new AbortController();
const rpc = createRpcClient({
baseUrl: '/api',
signal: clientCtrl.signal,
});
await rpc.query('data', input, {
signal: callCtrl.signal, // combined with clientCtrl.signal
});Error Handling
Timeouts and manual aborts throw a DOMException, not an RpcError.
try {
await rpc.query('slow_query', input, { timeout: 5000 });
} catch (e) {
if (e instanceof DOMException && e.name === 'AbortError') {
// Timeout or manual abort — NOT an RpcError
console.log('Request timed out or was cancelled');
}
}Try it
The server sleeps for the requested duration. Client-side timeout fires an AbortError before the server responds.
Client Timeout
Server delay 1s, client timeout 2s (OK) vs server delay 1s, client timeout 300ms (abort).
Manual Abort
Start a 10s request, then cancel it with AbortController.