mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
successResponse() used NextResponse.json(), which calls JSON.stringify and throws on BigInt. Prisma returns BigInt for VideoVersion.sizeBytes and VideoAsset.sizeBytes, so any route returning one of those rows returned 500 after its database write had already committed. #27 fixed two such endpoints by narrowing their selects, and two create routes were already wrapped in toJsonSafe(). This closes the bug class at the helper instead: successResponse() now serializes with a shared bigIntReplacer, which covers every route in app/api (none construct a NextResponse.json response directly). The two toJsonSafe() call sites are now redundant and were removed. BigInt values render as strings, matching what toJsonSafe already produced.
19 lines
686 B
TypeScript
19 lines
686 B
TypeScript
/**
|
|
* JSON.stringify replacer that renders Prisma BigInt columns (sizeBytes) as
|
|
* strings. Without it, JSON.stringify throws on any payload carrying one.
|
|
*/
|
|
export function bigIntReplacer(_key: string, value: unknown): unknown {
|
|
return typeof value === 'bigint' ? value.toString() : value;
|
|
}
|
|
|
|
/**
|
|
* Converts values for JSON responses (e.g. Prisma BigInt fields).
|
|
*
|
|
* API routes do not need this — successResponse() serializes BigInt already.
|
|
* Use it for payloads that bypass that helper, such as data handed from a
|
|
* server component to a client component.
|
|
*/
|
|
export function toJsonSafe<T>(value: T): T {
|
|
return JSON.parse(JSON.stringify(value, bigIntReplacer)) as T;
|
|
}
|