Prisma + D1 fails when external API returns 429 error in Cloudflare Workers
Issue
When an external API (CoinGecko) returns a 429 error, subsequent Prisma queries to D1 fail with:
Environment
- Cloudflare Workers
- D1 Database
- Prisma with D1 adapter
- Axios for HTTP requests
Minimal Reproduction
What I've Tried
1. Wrapping the API call in try-catch
2. Using separate try-catch blocks
3. Adding delays between API call and database operation
4. Logging the data being inserted (it's identical in both cases)
Questions
1. Why does a 429 error from an external API affect subsequent D1/Prisma operations?
2. Is this a known issue with Cloudflare Workers context corruption?
3. Are there any workarounds besides switching from axios to fetch?
Additional Context
- The issue ONLY occurs when the external API returns 429
- The exact same database insert data works when the API succeeds
- The error suggests D1 is receiving malformed data, but we're not sending any data from the API response
Any insights would be greatly appreciated!
0 Replies