Skip to content

feat(core): add shared API error type for packages and apps - #373

Open
huangji6693-max wants to merge 1 commit into
nexoraorg:mainfrom
huangji6693-max:feat/shared-api-error-type-311
Open

huangji6693-max wants to merge 1 commit into
nexoraorg:mainfrom
huangji6693-max:feat/shared-api-error-type-311

Conversation

@huangji6693-max

Copy link
Copy Markdown

Summary

Closes #311

Defines and exports a shared, serializable API error contract (ApiErrorPayload, ApiErrorCode, createApiErrorPayload, isApiErrorPayload, toUnknownApiErrorPayload, and normalizeClientError) in @chenaikit/core and adopts it across backend and frontend error-handling paths.

Changes Included

  • packages/core/src/errors.ts & packages/core/src/index.ts:
    • Added ApiErrorPayload (error, message, optional statusCode, requestId, details, retryAfter) and API_ERROR_CODES / ApiErrorCode.
    • Added createApiErrorPayload and sanitizeErrorDetails to omit undefined properties and strip sensitive keys (stack, stackTrace, cause, sql, raw, password, secret, token, authorization) before serialization.
    • Added isApiErrorPayload type guard so SDK and application consumers can narrow structured API error responses safely.
    • Added toUnknownApiErrorPayload and normalizeClientError so unexpected failures are converted into safe user-facing payloads without leaking raw internals.
  • packages/core/test/core.test.ts:
    • Added unit tests covering JSON round-trip serialization, detail sanitization, runtime type narrowing, unknown error fallback redaction, and client error normalization.
  • apps/backend/src/middleware/errorHandler.ts & apps/backend/src/middleware/errorHandler.test.ts:
    • Adopted ApiErrorPayload, createApiErrorPayload, and toUnknownApiErrorPayload from @chenaikit/core in buildErrorBody and the 500 fallback handler, with test assertions verifying isApiErrorPayload(res.body).
  • apps/frontend/src/components/ErrorBoundary.tsx & apps/frontend/src/components/ErrorBoundary.test.tsx:
    • Adopted normalizeClientError from @chenaikit/core to safely render structured API error messages and optional Request ID metadata in the error boundary fallback UI.

Testing done

  • pnpm --filter @chenaikit/core run lint && pnpm --filter @chenaikit/core run test && pnpm --filter @chenaikit/core run build
  • cd apps/backend && pnpm run lint && pnpm exec tsc -p tsconfig.json --noEmit && pnpm run test && pnpm run build
  • cd apps/frontend && npm run lint && npx --no-install tsc --noEmit && npm run test && npx --no-install vite build

Screenshots

N/A — internal error-handling normalization and optional Request ID: <id> diagnostic line in ErrorBoundary fallback alert verified via React Testing Library (apps/frontend/src/components/ErrorBoundary.test.tsx).

Checklist

  • Shared error type is exported from @chenaikit/core
  • Consumers can narrow structured API errors safely via isApiErrorPayload and normalizeClientError
  • Unknown errors are converted without leaking sensitive internals

@vercel

vercel Bot commented Oct 27, 2026

Copy link
Copy Markdown

@huangji6693-max is attempting to deploy a commit to the Isaac Gellu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6be81d09-eaa1-4842-87a2-e5fcbe60d4b8
Commits

Reviewing files that changed from the base of the PR and between 2653a3f and da1fd28.

Files selected for processing: 12
  • apps/backend/package.json
  • apps/backend/src/index.ts
  • apps/backend/src/middleware/errorHandler.test.ts
  • apps/backend/src/middleware/errorHandler.ts
  • apps/backend/tsconfig.json
  • apps/frontend/src/components/ErrorBoundary.test.tsx
  • apps/frontend/src/components/ErrorBoundary.tsx
  • apps/frontend/tsconfig.json
  • apps/frontend/vite.config.ts
  • packages/core/src/errors.ts
  • packages/core/src/index.ts
  • packages/core/test/core.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

Add a shared API error type for packages and applications

1 participant