Skip to content

feat(architecture): Add ResponseInterceptor for consistent API response envelope (#839)#401

Open
Gezziy wants to merge 1 commit into
code-flexing:mainfrom
Gezziy:add-response-interceptor
Open

feat(architecture): Add ResponseInterceptor for consistent API response envelope (#839)#401
Gezziy wants to merge 1 commit into
code-flexing:mainfrom
Gezziy:add-response-interceptor

Conversation

@Gezziy
Copy link
Copy Markdown

@Gezziy Gezziy commented May 31, 2026

closes #374

Summary of Changes

  • New Interceptor: Created ResponseInterceptor in src/common/interceptors/response.interceptor.ts to wrap all REST API success responses inside a standard { data, meta } envelope.
  • Envelope Handling:
    • Standardizes raw arrays, objects, and primitives into { data: response, meta: {} }.
    • Auto-normalizes legacy pagination objects like { items: T[], total: number } or { data: T[], total: number } to { data: items, meta: { total } }.
    • Preserves already enveloped { data, meta } payloads without double-wrapping.
  • Context & Safety Bypasses:
    • Automatically bypasses non-HTTP contexts (e.g., GraphQL queries/mutations and WebSocket connections).
    • Safely bypasses raw file downloads (detects response.headersSent, 204 No Content, 304 Not Modified, Buffer payloads, and StreamableFile instances).
  • Global Registration: Registered ResponseInterceptor globally in main.ts.
  • Unit Testing: Added 16 comprehensive unit tests in src/common/interceptors/response.interceptor.spec.ts validating all formatting rules and bypass cases.

Reason for Changes

Currently, REST API endpoints return inconsistent shapes (some raw arrays, some pagination objects, some enveloped objects). This forces the frontend to write custom parsing logic for each endpoint. Standardizing on a { data, meta } envelope allows the client to process responses consistently.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@TochukwuJustice is attempting to deploy a commit to the vic's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

@Gezziy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

#839 Add ResponseInterceptor for consistent API response envelope

2 participants