UNPKG

zod-server-actions

Version:

Simple utility library to create server actions in Next.js

20 lines (19 loc) 654 B
import { sleep } from "./sleep"; import { logger } from "../core/logger"; export async function makeRetries(props) { if (!props.config || !props.config.retries) return null; for (let i = 0; i < props.config.retries.maximumAttempts; i++) { try { if (props.config.debug) logger.debug("Making request: ", i + 1); return await props.cb(props.input, props.config.context); } catch (error) { if (props.config.debug) logger.error("Request error: ", error.message); await sleep(props.config.retries.delay); } } return null; }