Skip to content
awekrx edited this page May 29, 2026 · 1 revision

retry

Import

import { retry } from '@dev-suite/decorators/retry'

Category

  • method

Use Case

Retry transient failures with explicit and reusable policy.

Replaces

  • Inline retry loops and backoff logic
  • Inconsistent retry handling per method

Example 1

Without decorator

class BillingClient {
  async charge(input: ChargeInput) {
    for (let attempt = 1; attempt <= 3; attempt += 1) {
      try {
        return await this.http.post('/charge', input);
      } catch (error) {
        if (attempt === 3) throw error;
        await sleep(250);
      }
    }
  }
}

With decorator

import { retry } from '@dev-suite/decorators/retry';

class BillingClient {
  @retry({ attempts: 3, delayMs: 250 })
  async charge(input: ChargeInput) {
    return this.http.post('/charge', input);
  }
}

Why better

  • Retry policy is centralized and easy to audit.
  • No control-flow clutter inside business methods.

Example 2

Without decorator

class SyncService {
  async push(batch: Batch) {
    try {
      return await this.remote.push(batch);
    } catch (error) {
      if (!isTransient(error)) throw error;
      return this.remote.push(batch);
    }
  }
}

With decorator

import { retry } from '@dev-suite/decorators/retry';

class SyncService {
  @retry({ attempts: 4, shouldRetry: (error) => isTransient(error) })
  async push(batch: Batch) {
    return this.remote.push(batch);
  }
}

Why better

  • Selective retry avoids retrying permanent failures.
  • Behavior can be aligned across multiple clients.

Clone this wiki locally