Skip to content

fix: handle BigInt serialization in REST API v1 detail endpoints#53

Merged
TerrifiedBug merged 1 commit intomainfrom
fix/api-v1-bigint-serialization
Mar 7, 2026
Merged

fix: handle BigInt serialization in REST API v1 detail endpoints#53
TerrifiedBug merged 1 commit intomainfrom
fix/api-v1-bigint-serialization

Conversation

@TerrifiedBug
Copy link
Copy Markdown
Owner

Summary

  • GET /api/v1/pipelines/:id and GET /api/v1/nodes/:id return HTTP 500 because NodePipelineStatus contains BigInt fields (eventsIn, eventsOut, errorsTotal, etc.) that JSON.stringify() cannot serialize
  • Adds a jsonResponse() helper in api-handler.ts that uses a custom JSON replacer to convert BigInts to numbers
  • Updates both detail route handlers to use jsonResponse() instead of NextResponse.json()

Test plan

  • GET /api/v1/pipelines/:id returns 200 with pipeline detail including nodeStatuses
  • GET /api/v1/nodes/:id returns 200 with node detail including pipelineStatuses
  • All other v1 endpoints continue to work (they don't return BigInt fields)

GET /api/v1/pipelines/:id and /api/v1/nodes/:id return 500 because
NodePipelineStatus contains BigInt fields (eventsIn, eventsOut, etc.)
that JSON.stringify cannot serialize. Adds a jsonResponse() helper
using a custom replacer to convert BigInts to numbers.
@github-actions github-actions bot added the fix label Mar 7, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR fixes a real HTTP 500 bug on GET /api/v1/pipelines/:id and GET /api/v1/nodes/:id caused by JSON.stringify() failing on BigInt fields returned from Prisma's NodePipelineStatus model. The fix is minimal and well-scoped: a single jsonResponse() helper is added in the shared api-handler.ts and used at the two affected success paths, leaving all error responses unchanged.

Changes:

  • api-handler.ts — adds jsonResponse() with a custom JSON replacer that converts BigInt → Number before handing off to NextResponse
  • pipelines/[id]/route.ts — uses jsonResponse() on the 200 success path
  • nodes/[id]/route.ts — uses jsonResponse() on the 200 success path

The implementation correctly addresses the root cause with minimal surface area. All error paths remain untouched, and existing auth/permission middleware is preserved.

Confidence Score: 5/5

  • Safe to merge — fixes a real crash with a targeted, low-risk change.
  • The fix correctly addresses the root cause (BigInt serialization) with minimal surface area. The changes are localized to two detail endpoints and a shared helper. All error paths remain untouched. Auth and permission middleware are preserved. No concerning edge cases or breaking changes introduced.
  • No files require special attention.

Sequence Diagram

sequenceDiagram
    participant C as API Client
    participant R as Route Handler
    participant P as Prisma (PostgreSQL)
    participant J as jsonResponse()

    C->>R: GET /api/v1/pipelines/:id (or /nodes/:id)
    R->>R: authenticateApiKey() + hasPermission()
    R->>P: findUnique({ select: { nodeStatuses: { eventsIn, eventsOut, errorsTotal } } })
    P-->>R: Record with BigInt fields (e.g. eventsIn: 42n)
    R->>J: jsonResponse({ pipeline })
    J->>J: JSON.stringify(data, BigInt → Number replacer)
    J-->>C: 200 OK, Content-Type: application/json<br/>{ "pipeline": { "nodeStatuses": [{ "eventsIn": 42 }] } }
Loading

Last reviewed commit: 1a0f5e6

@TerrifiedBug TerrifiedBug merged commit bbcb3a7 into main Mar 7, 2026
12 checks passed
@TerrifiedBug TerrifiedBug deleted the fix/api-v1-bigint-serialization branch March 7, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant