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.
Repository: shapeshift/unchained
Location: node/proxy/api/src/affiliateRevenue/index.ts
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
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)
}
})