Skip to content

Product route: No try/catch error handling in route handlers #18

@thomasiverson

Description

@thomasiverson

Severity: Medium

Category: Error Handling

Description

In api/src/routes/product.ts, none of the route handlers have try/catch blocks. If req.body causes an unexpected error (e.g., JSON parsing edge cases), it would result in an unhandled exception and potentially crash the process or return a generic 500.

Suggested Fix

Wrap handlers in try/catch or add Express error-handling middleware:

router.post('/', (req, res) => {
  try {
    const newProduct: Product = req.body;
    products.push(newProduct);
    res.status(201).json(newProduct);
  } catch (error) {
    res.status(500).json({ error: 'Internal server error' });
  }
});

Alternatively, add a centralized error handler in api/src/index.ts.

Affected File

  • api/src/routes/product.ts (all handlers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions