Skip to content

chore: Improve Error Handling in API Routes #31

Description

@SujalTripathi

Description

The existing API routes (/api/bookings, /api/instructors) have minimal
or no error handling. Missing validation and unstructured error responses
make debugging difficult and expose the API to bad inputs.

Current Behavior

  • No input validation on POST /api/bookings
  • Generic or no error responses returned
  • No HTTP status codes used correctly
  • No handling for missing required fields

Expected Behavior

  • All required fields validated before processing
  • Correct HTTP status codes: 400 (bad input), 404 (not found), 500 (server error)
  • Structured JSON error responses: { error: "message" }
  • Try/catch blocks around all async operations

Acceptance Criteria

  • Input validation added to POST /api/bookings
  • Correct status codes returned
  • Structured { error: "..." } JSON responses
  • Try/catch on all async API handlers
  • Missing field errors return 400 with field name

Contributing on behalf of NSoC'26 | @Mehren7 please assign me

Metadata

Metadata

Assignees

Labels

Level2INTERMEDITE LEVELNSoC'26NSoc'26 program trackingenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions