-
Notifications
You must be signed in to change notification settings - Fork 0
Product route: No try/catch error handling in route handlers #18
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working