Skip to content

Exercise 6: Mask Database Schema Error Messages in Production #9

Description

@harsharajkumar-273

Goal

Secure the gateway API response format from leaking system implementation details.

Problem

In src/middleware/errorHandler.ts, if an unexpected 500 error is thrown (such as a database query timeout or table constraint error), the raw SQL error message err.message is returned to the client inside the JSON response even in production, exposing database structure details.

Task

  1. Update src/middleware/errorHandler.ts to inspect the environment.
  2. If env.NODE_ENV === 'production' and the response status is 500, mask the response message to a generic 'Internal Server Error' string.
  3. Ensure the detailed error log remains printed to console.error for secure diagnostics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions