Commit e3efea2
committed
refactor: Improve POST /messages validation with type checking
- Add check for req.body existence before destructuring
- Add type validation to ensure text and sender are strings
- Replace simple falsy check with .trim() for whitespace validation
- Return specific error messages for each validation failure
- Improve error handling clarity with separate validation steps
- Prevent type coercion errors and invalid data submission1 parent 8972d95 commit e3efea2
1 file changed
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | | - | |
20 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
21 | 31 | | |
22 | 32 | | |
23 | 33 | | |
| |||
0 commit comments