Performance: Validation error response formatting
MEDIUM IMPACT
This affects the server response time and client rendering speed by how validation errors are formatted and sent.
app.post('/user', (req, res) => { const errors = []; if (!req.body.email) errors.push({ field: 'email', message: 'Email is required' }); if (!req.body.password) errors.push({ field: 'password', message: 'Password is required' }); if (errors.length > 0) { res.status(400).json({ errors }); } else { res.json({ success: true }); } });
app.post('/user', (req, res) => { const errors = []; if (!req.body.email) errors.push('Email is required'); if (!req.body.password) errors.push('Password is required'); if (errors.length > 0) { res.status(400).send({ message: errors.join(', ') }); } else { res.send({ success: true }); } });
| Pattern | Payload Size | Client Parsing | Network Overhead | Verdict |
|---|---|---|---|---|
| Concatenated error string | Larger due to combined messages | High parsing cost | Moderate | [X] Bad |
| Structured JSON errors | Smaller and clear | Low parsing cost | Low | [OK] Good |