fix(scan): convert BigInt in data API jsonResponse to prevent 500s#694
Merged
fix(scan): convert BigInt in data API jsonResponse to prevent 500s#694
Conversation
…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.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/api/data/resources/searchand/api/data/resourcesendpoints return 500 errors because Prisma returnsmaxAmountRequiredas BigInt, andNextResponse.json()callsJSON.stringifywhich can't serialize BigInt.Error:
TypeError: Do not know how to serialize a BigIntChanges
sanitizeBigInts()helper indata/_lib/utils.tsthat recursively converts BigInt values to stringsjsonResponse()— this covers all data API routes since bothjsonResponseandpaginatedResponseflow through itAudit of affected routes
All routes under
/api/data/usejsonResponseorpaginatedResponsefrom the shared utils, so they're all covered:/api/data/resources/search— confirmed broken (the reported route)/api/data/resources— confirmed broken (HEAD returns 500)/api/data/origins/[id]/resources— has manualserializeAcceptsbut 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 safeRoutes outside
/api/data/useNextResponse.jsondirectly 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 500HEAD /api/data/resources— should return 200GET /api/data/resources— verifymaxAmountRequiredappears as string in JSON