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)
Severity: Medium
Category: Error Handling
Description
In
api/src/routes/product.ts, none of the route handlers havetry/catchblocks. Ifreq.bodycauses 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:
Alternatively, add a centralized error handler in
api/src/index.ts.Affected File
api/src/routes/product.ts(all handlers)