Skip to content

Add Graceful Error Handling to Affiliate Revenue Endpoint #1248

@premiumjibles

Description

@premiumjibles

Context

The ShapeShift affiliate revenue API aggregates fee data from multiple external swap provider APIs (0x, Bebop, THORChain, Chainflip, Portals, MAYAChain). The endpoint fetches from all providers in parallel and returns combined results.

Current Problem: If any single provider API fails (e.g., Bebop is down), the entire request fails and returns no data. This is because the code uses Promise.all() which rejects if any promise rejects.

Current Implementation

Location: node/proxy/api/src/affiliateRevenue/index.ts

// Current code - if one fails, all fail
const [zrxFees, bebopFees, ...] = await Promise.all([
  zrx.getFees(startTimestamp, endTimestamp),
  bebop.getFees(startTimestamp, endTimestamp),
  // ... other providers
])

Solution

Use Promise.allSettled() to handle partial failures gracefully. Return successful data even if some providers fail, and log/report which providers had errors.

Acceptance Criteria

  • Replace Promise.all() with Promise.allSettled()
  • Aggregate fees from successful providers
  • Log failed providers with error details (console.error or structured logging)
  • Response returns partial data when some providers fail
  • No breaking changes to response schema for the success case

Files to Modify

  • node/proxy/api/src/affiliateRevenue/index.ts

Implementation Guidance

const results = await Promise.allSettled([
  zrx.getFees(start, end),
  bebop.getFees(start, end),
  // ...
])

const fees: Fees[] = []
results.forEach((result, index) => {
  if (result.status === 'fulfilled') {
    fees.push(...result.value)
  } else {
    console.error(`[AffiliateRevenue] ${serviceNames[index]} failed:`, result.reason)
  }
})

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions