Skip to content

fix(scan): convert BigInt in data API jsonResponse to prevent 500s#694

Merged
rsproule merged 1 commit intomainfrom
craig/fix-bigint-search-serialization
Mar 8, 2026
Merged

fix(scan): convert BigInt in data API jsonResponse to prevent 500s#694
rsproule merged 1 commit intomainfrom
craig/fix-bigint-search-serialization

Conversation

@craigbidenbot
Copy link
Contributor

@craigbidenbot craigbidenbot bot commented Mar 8, 2026

Summary

The /api/data/resources/search and /api/data/resources endpoints return 500 errors because Prisma returns maxAmountRequired as BigInt, and NextResponse.json() calls JSON.stringify which can't serialize BigInt.

Error: TypeError: Do not know how to serialize a BigInt

Changes

  • Added sanitizeBigInts() helper in data/_lib/utils.ts that recursively converts BigInt values to strings
  • Applied it in jsonResponse() — this covers all data API routes since both jsonResponse and paginatedResponse flow through it

Audit of affected routes

All routes under /api/data/ use jsonResponse or paginatedResponse from the shared utils, so they're all covered:

  • /api/data/resources/searchconfirmed broken (the reported route)
  • /api/data/resourcesconfirmed broken (HEAD returns 500)
  • /api/data/origins/[id]/resources — has manual serializeAccepts but now also has safety net
  • /api/data/facilitators, /merchants, /wallets — less likely to have BigInt but now safe
  • /api/data/registry/register — could receive BigInt from upsert results, now safe

Routes outside /api/data/ use NextResponse.json directly but don't serialize Prisma resource results with BigInt fields.

The tRPC routes don't have this issue because they use SuperJSON.

Test Plan

  • GET /api/data/resources/search?q=image+generation — should return results instead of 500
  • HEAD /api/data/resources — should return 200
  • GET /api/data/resources — verify maxAmountRequired appears as string in JSON

…n errors

searchResources returns Prisma results with BigInt maxAmountRequired fields.
NextResponse.json calls JSON.stringify which throws 'Do not know how to
serialize a BigInt'. Add recursive sanitization in jsonResponse to convert
BigInts to strings before serialization.
@vercel
Copy link
Contributor

vercel bot commented Mar 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402scan Ready Ready Preview, Comment Mar 8, 2026 0:19am

@rsproule rsproule merged commit 8474abb into main Mar 8, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant