| name | oRPC Client Retry Plugin |
| description | A plugin for oRPC that enables retrying client calls when errors occur. |
| license | MIT |
| metadata | {"author":"Ali Torki","homepage":"https://github.com/ali-master","version":"1.0.0"} |
Client Retry Plugin
The Client Retry Plugin enables retrying client calls when errors occur.
Setup
import { RPCLink } from '@orpc/client/fetch'
import { ClientRetryPlugin, ClientRetryPluginContext } from '@orpc/client/plugins'
interface ORPCClientContext extends ClientRetryPluginContext {}
const link = new RPCLink<ORPCClientContext>({
url: 'http://localhost:3000/rpc',
plugins: [
new ClientRetryPlugin({
default: {
retry: ({ path }) => {
if (path.join('.') === 'planet.list') return 2
return 0
}
},
}),
],
})
const client: RouterClient<typeof router, ORPCClientContext> = createORPCClient(link)
The link can be any oRPC link — RPCLink, OpenAPILink, or custom implementations.
Usage
const planets = await client.planet.list({ limit: 10 }, {
context: {
retry: 3,
retryDelay: 2000,
shouldRetry: options => true,
onRetry: (options) => {
return (isSuccess) => {
}
},
}
})
Defaults:
retry: 0 (disabled unless explicitly set)
retryDelay: (o) => o.lastEventRetry ?? 2000
shouldRetry: true
Event Iterator (SSE)
Replicate EventSource behavior:
const streaming = await client.streaming('the input', {
context: { retry: Number.POSITIVE_INFINITY }
})
for await (const message of streaming) {
console.log(message)
}