Skip to content

Implement centralized backend error handling and validation for REST APIs #53

@AadiSharma49

Description

@AadiSharma49

The current FitFinder backend (built using Node.js/Express with TypeScript) does not consistently handle errors across API routes. This leads to inconsistent responses (default HTML error pages, unstructured error messages), making it difficult for frontend clients to handle errors reliably and safely.

We should implement a global error handling middleware and standardized error response format, plus add request validation for all endpoints to catch malformed or invalid requests before they reach business logic.

Problem

The backend currently does not have centralized error handling or request validation. Inconsistent error responses and leaked stack traces make it difficult for frontend clients to handle errors and poses potential security risks.

Solution

Implement a global error handling middleware in Express and enforce standardized JSON error responses across all API routes. Add request validation to ensure API inputs are correct.

Acceptance Criteria

  • Centralized error handler middleware added
  • 404 handler for unknown routes
  • Validation errors return structured messages
  • Internal errors return safe generic message
  • No stack traces exposed in API responses

Manual Testing

  1. GET /unknown-route
  2. Submit invalid body to existing route
  3. Force an exception inside route handler

Backend architecture improvement

Security sensitivity (no stack traces)

WOCS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions