Skip to content

Feat implement centralized error handling for API routes#474

Open
Aryanshravan wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Aryanshravan:feat/issue-470-improve-error-handling
Open

Feat implement centralized error handling for API routes#474
Aryanshravan wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
Aryanshravan:feat/issue-470-improve-error-handling

Conversation

@Aryanshravan
Copy link
Copy Markdown

@Aryanshravan Aryanshravan commented May 20, 2026

Summary

Implements centralized error handling across API routes to improve debugging and error tracking consistency.

Closes #470

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup

Changes Made

  • Created src/lib/error-handler.ts with centralized error logging utilities
    • logError() - Logs errors with timestamp, endpoint, operation, and context
    • createErrorResponse() - Standardized error response format
    • handleAPIError() - Helper function for consistent error handling
  • Updated 3 API routes to use centralized error handler:
    • src/app/api/badge/commits/route.ts
    • src/app/api/badge/streak-shield/route.ts
    • src/app/api/webhooks/github/route.ts
  • All errors now include: timestamp, endpoint, operation, user ID, and context

How to Test

  1. Test an API route with invalid input (e.g., /api/badge/commits without user param)
  2. Check browser console or server logs for error output
  3. Verify error logs include timestamp, endpoint, operation, and context
  4. Verify error response format is consistent across all routes
  5. Verify error messages don't expose sensitive information

Checklist

  • Linked issue in summary
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Self-reviewed the diff
  • Error handling is consistent across routes
  • No sensitive data leaked in error messages

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@Aryanshravan is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:docs GSSoC type bonus: documentation (+5 pts) type:feature GSSoC type bonus: new feature labels May 20, 2026
@github-actions
Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first PR on DevTrack! 🎉

A maintainer will review it within 48 hours. While you wait:

  • Make sure CI is passing (type-check + lint)
  • Double-check the PR description is filled out and the issue is linked
  • Feel free to ask questions in Discussions if you need help

If you find DevTrack useful, a ⭐ star on the repo is always appreciated — it helps the project grow and attract more contributors!

Copy link
Copy Markdown
Owner

@Priyanshu-byte-coder Priyanshu-byte-coder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three issues:

  1. Remove CODEBASE_ISSUES.md — an AI-generated 708-line analysis dump doesn't belong in the repo. This file alone blocks merge.

  2. handleAPIError and createErrorResponse are dead code — exported from error-handler.ts but never called in the changed routes (which call logError directly). Either use them or remove them from the PR scope.

  3. logError exposes raw stack traces in productionconsole.error(JSON.stringify(logEntry)) includes error and stack fields unconditionally. Gate stack traces behind process.env.NODE_ENV !== 'production' to avoid leaking internals (same pattern PR #472 just fixed in the error boundary).

@Priyanshu-byte-coder Priyanshu-byte-coder added the level:intermediate GSSoC: Intermediate difficulty (35 pts) label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution level:intermediate GSSoC: Intermediate difficulty (35 pts) type:docs GSSoC type bonus: documentation (+5 pts) type:feature GSSoC type bonus: new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Fix: Improve error handling in API routes - proper logging and error responses

2 participants