JavaScript Code Style
This skill provides JavaScript coding standards for the ECP codebase. After writing code, note the code rules applied, e.g. "Applied: 1.1 - Always wrap async route handlers in try-catch".
Rules
- •Error Handling
- •Always wrap async Express route handlers in try-catch blocks. The ECP API
has no global error middleware, so unhandled promise rejections cause
requests to hang indefinitely until timeout. Note: This does NOT apply to
database migrations (
api/migrations/) - migrate-mongo handles errors at the framework level. - •Use
setErrorResponse(res, title, detail, status)from../lib/http.jsfor error responses. - •Log errors with
console.error()before returning error response. - •Return 400 for client errors (validation, bad input), 500 for server errors (database failures, unexpected exceptions).
- •Example:
javascript
router.post('/endpoint', async (req, res) => { try { // ... route logic res.json(result); } catch (error) { console.error('Error in /endpoint:', error); return setErrorResponse(res, 'Operation failed', error.message, 500); } });
- •Always wrap async Express route handlers in try-catch blocks. The ECP API
has no global error middleware, so unhandled promise rejections cause
requests to hang indefinitely until timeout. Note: This does NOT apply to
database migrations (