Execute a function with automatic retries on failure.
Copy
import { executeWithRetries } from '@orion-js/helpers'// Execute a function with 3 retries and 200ms timeout between attemptsconst result = await executeWithRetries(async () => { // Your async function that might fail return await fetchData()}, 3, 200)
import { UserError } from '@orion-js/helpers'// Basic usagethrow new UserError('Invalid input')// With error codethrow new UserError('invalid_input', 'Please provide a valid email')// With extra datathrow new UserError('invalid_input', 'Please provide a valid email', { field: 'email' })
All error classes provide helpful methods to access error information:
Copy
try { // ...} catch (error) { if (error.isOrionError) { // Get standardized error information const info = error.getInfo() console.log(info.error) // Error code console.log(info.message) // Error message console.log(info.extra) // Extra data if (error.isUserError) { // Can be shown to the user } if (error.isPermissionsError) { // Handle permissions issues } }}