Add Graceful Error Handling to Affiliate Revenue Endpoint
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()withPromise.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)
}
})
๐ CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
- [ ] Create Plan
๐ Related PRs
shapeshift/web#10202 - feat: enable butter same chain swaps [merged] shapeshift/web#10372 - feat: allow quotes that take longer than 5 seconds to keep going if we get nothing else [merged] shapeshift/web#11010 - fix: swapper gas fixes [merged] shapeshift/web#11283 - fix: implement proper TRON getTransaction and fix Sun.io status checking [merged] shapeshift/unchained#1228 - feat: affiliate revenue tracker and endpoint [closed]
๐ค Suggested Assignees
๐งช Issue enrichment is currently in open beta.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
๐ฌ Have feedback or questions? Drop into our discord or schedule a call!
๐ CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
- [ ] Create Plan
๐ Similar Issues
Possible Duplicates
- https://github.com/shapeshift/web/issues/11435
Related Issues
- https://github.com/shapeshift/unchained/issues/1234
- https://github.com/shapeshift/web/issues/11461
๐ Related PRs
shapeshift/web#10372 - feat: allow quotes that take longer than 5 seconds to keep going if we get nothing else [merged] shapeshift/web#11010 - fix: swapper gas fixes [merged] shapeshift/unchained#1228 - feat: affiliate revenue tracker and endpoint [merged] shapeshift/web#11446 - fix: cetus token to SUI swap gas estimation [merged] shapeshift/web#11448 - feat: exclude Pyth-dependent providers from Cetus swaps [merged]
๐ค Suggested Assignees
๐งช Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
๐ฌ Have feedback or questions? Drop into our discord or schedule a call!